package com.Fly.HBXT.Service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.Fly.HBXT.model.UserImage;
import gov.Fly.HB.Verhicle.DB.DBConnection;
public class FileUploadService extends delFiles{
List<UserImage> c=new ArrayList<UserImage>();
DBConnection conn=new DBConnection();
Connection con=null;
PreparedStatement pst=null;
ResultSet rs=null;
int sqli=1;
public int fileupload (String kk[]) throws SQLException{
int flag=1;
DBConnection db = new DBConnection();
con=db.getConnection();
String sql="insert into image values(null,?,?,?,?)";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[1]);
pst.setString(3, kk[2]);
pst.setString(4, kk[3]);
int falg=pst.executeUpdate();
if(flag>0){
System.out.println("上传成功");
}else{
System.out.println("上传失败");
}
return flag;
}
public List findAllPages () throws SQLException{
DBConnection db = new DBConnection();
con=db.getConnection();
UserImage iamge=null;
String sql="select * from image";
pst= con.prepareStatement(sql);
rs=pst.executeQuery();
while(rs.next()){
iamge=new UserImage();
iamge.setId(rs.getInt("id"));
iamge.setImages1(rs.getString("image1"));
iamge.setImages2(rs.getString("image2"));
iamge.setImages3(rs.getString("image3"));
iamge.setImages4(rs.getString("image4"));
c.add(iamge);
}
System.out.println("查看所有图片"+sql);
return c;
}
public UserImage findUserImageById (int id) throws SQLException{
DBConnection db = new DBConnection();
con=db.getConnection();
UserImage iamge=new UserImage();
String sql="select * from image where id=?";
pst= con.prepareStatement(sql);
pst.setInt(1, id);
rs=pst.executeQuery();
while(rs.next()){
iamge.setImages1(rs.getString("image1"));
iamge.setImages2(rs.getString("image2"));
iamge.setImages3(rs.getString("image3"));
iamge.setImages4(rs.getString("image4"));
iamge.setId(rs.getInt("id"));
}
return iamge;
}
public int updateUserImage (String kk[] ,int id,String path,UserImage image) throws SQLException{
int flag=0;
DBConnection db = new DBConnection();
String sql="";
con=db.getConnection();
String image1=kk[0];
String image2=kk[1];
String image3=kk[2];
String image4=kk[3];
//全改
if(image1!=null&&image2!=null&& image3!=null&& image4!=null){
sql="update image set image1=?,image2=?,image3=?,image4=? where id=? ";
System.out.println("传过来的路径"+path);
getFiles(path,image);
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[1]);
pst.setString(3, kk[2]);
pst.setString(4, kk[3]);
pst.setInt(5, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//只改第一个
else if(image1!=null&&image2==null&& image3==null&& image4==null){
sql="update image set image1=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setInt(2, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//只改第二个
else if(image1==null&&image2!=null&& image3==null&& image4==null){
sql="update image set image2=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[1]);
pst.setInt(2, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//只改第3个
else if(image1==null&&image2==null&& image3!=null&& image4==null){
sql="update image set image3=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[2]);
pst.setInt(2, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//只改第4个
else if(image1!=null&&image2==null&& image3!=null&& image4==null){
sql="update image set image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[3]);
pst.setInt(2, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,2
else if(image1!=null&&image2!=null&& image3==null&& image4==null){
sql="update image set image1=?,image2=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[1]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,3
else if(image1!=null&&image2==null&& image3!=null&& image4==null){
sql="update image set image1=?,image3=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[2]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,4
else if(image1!=null&&image2!=null&& image3!=null&& image4==null){
sql="update image set image1=?,image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[3]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改2,3
else if(image1==null&&image2!=null&& image3!=null&& image4==null){
sql="update image set image2=?,image3=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[1]);
pst.setString(2, kk[2]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改2,4
else if(image1==null&&image2!=null&& image3==null&& image4!=null){
sql="update image set image2=?,image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[1]);
pst.setString(2, kk[3]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改3,4
else if(image1==null&&image2==null&& image3!=null&& image4!=null){
sql="update image set image3=?,image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[2]);
pst.setString(2, kk[3]);
pst.setInt(3, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,2,3
else if(image1!=null&&image2!=null&& image3!=null&& image4==null){
sql="update image set image1=?,image2=?,image3=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[1]);
pst.setString(3, kk[2]);
pst.setInt(4, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,2,4
else if(image1!=null&&image2!=null&& image3==null&& image4!=null){
sql="update image set image1=?,image2=?,image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[1]);
pst.setString(3, kk[3]);
pst.setInt(4, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改1,3,4
else if(image1!=null&&image2==null&& image3!=null&& image4!=null){
sql="update image set image1=?,image3=?,image3=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[0]);
pst.setString(2, kk[2]);
pst.setString(3, kk[3]);
pst.setInt(4, id);
flag=pst.executeUpdate();
System.out.println("DAO提交结果"+flag);
}
//改2,3,4
else if(image1==null&&image2!=null&& image3!=null&& image4!=null){
sql="update image set image2=?,image3=?,image4=? where id=? ";
pst= con.prepareStatement(sql);
pst.setString(1, kk[1]);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
UpdateImage.zip (45个子文件)
JSP_word
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
src
test
delFiles.java 5KB
listFile.java 1KB
gov
Fly
HB
Verhicle
DB
mdb.java 4KB
MdbConnection.java 70B
tt.mdb 1.69MB
DBConnection.java 859B
com
Fly
HBXT
Service
FileUploadService.java 8KB
delFiles.java 2KB
model
UserImage.java 776B
Servlet
FileUpload.java 3KB
findUserImageById.java 1KB
UpdateFileUpload.java 3KB
.project 1KB
WebRoot
readdoc.jsp 2KB
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 2KB
classes
test
delFiles.class 2KB
listFile.class 2KB
gov
Fly
HB
Verhicle
DB
mdb.class 3KB
tt.mdb 1.69MB
MdbConnection.class 310B
DBConnection.class 1KB
com
Fly
HBXT
Service
delFiles.class 2KB
FileUploadService.class 7KB
model
UserImage.class 1KB
Servlet
UpdateFileUpload.class 5KB
FileUpload.class 4KB
findUserImageById.class 2KB
lib
jspSmartUpload.jar 12KB
mysql-connector-java-5.0.5-bin.jar 501KB
FileUpload
uploadFile.html 1KB
do_upload.jsp 1KB
showPageById.jsp 2KB
showPage.jsp 2KB
index.jsp 831B
uploadedit.jsp 4KB
default.jsp 2KB
edit.jsp 4KB
ntkoocx.js 9KB
.mymetadata 297B
.classpath 532B
共 45 条
- 1
开心点点
- 粉丝: 13
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页