dao層書寫邏輯
public boolean savePic(String sql, String path, Picture picture) {
PreparedStatement pstmt = null;
if (path != null && path.trim() != "") {
try {
File file = new File(path);
InputStream in = new FileInputStream(file);
long len = file.length();
@SuppressWarnings("unused")
int leng = (int) len;
pstmt = dao.getConn().prepareStatement(sql);
pstmt.setBinaryStream(1, in, in.available());
pstmt.execute();
if (pstmt.execute()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
从DB层取数据写出到指定的盘符下
@SuppressWarnings("unchecked")
public boolean getPic(String sql) {
OutputStream out = null;
int i = 0;
// Vector v = new Vector();
// String pathName = null;
try {
ResultSet rs = dao.getConn().createStatement().executeQuery(sql);
while (rs.next()) {
i++;
// pathName = "E:/x" + i + ".jpg";
InputStream in = rs.getBinaryStream(1);
int len = in.available();
byte[] bytes = new byte[len * 100];
while (in.read(bytes) != -1) {
out = new FileOutputStream("E:/x" + i + ".jpg");
out.write(bytes);
// v.add(pathName);
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
action类书写
private Pic p = new Pic();
private Picture picture = new Picture();
//要针对对象必须有get/set方法
HttpServletRequest request = null;
public String savPicture() {
String sql = "insert into picture values(?)";
System.out.println(getPicture().getPicMemo() + "=================");
if (p.savePic(sql, getPicture().getPicMemo(), getPicture())) {
System.out.println("照片保存成功");
return SUCCESS;
}
System.out.println("照片保存失败");
return ERROR;
}
public String getpic() {
String sql = "select * from picture";
if (p.getPic(sql)) {
System.out.println("showPicture成功!");
return SUCCESS;
}
return ERROR;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
public Picture getPicture() {
return picture;
}
分享到:
相关推荐
图片压缩后保存在数据库,数据库表字段存储图片,小图片存储在数据库
取网页图片并保存DB V1.02.exe 取网页图片并保存DB V1.02.exe
最新的db2各版本链接下载地址,包括:db2从 8.2到9.7,从window到unix,linux ,从32位到84位的各个版本,绝对有你需要的那个版本! 不用注册直接下载,我用的就是在这上面的地址中下到的,绝对下得到!
DB中保存图片,web程序,和winform应该差不多
QQ2010版本软件采用了新的图片保存模式,以前是直接用文件夹,保存所有图片,现在用的DB数据库进行保存所有的个人QQ表情,聊天记录等信息,该文件位于你的QQ安装目录->Users->你的QQ号码->CustomFace.db文件。...
DB9 DB15 DB25 DB37 DB50 直型弯型针型孔型封装大全Altium库 PCB封装库90个合集(AD库): 封装型号列表: Component Count : 90 Component Name ----------------------------------------------- DB9 DB9 公 90° ...
DB2_V11.5安装包百度云下载
DB9 DB15 DB25 DB37 D型公头母头连接器3D封装库(STEP后缀)文件: Connector - d-sub.STEP DB-Female.STEP DB-Male.STEP DB15RA_F.STEP DB15RA_M.STEP DB15_F.STEP DB15_M.STEP DB25 .STEP DB25-F.STEP DB25-M.STEP...
calibre-web 数据库文件metadata.db 下载
直接将结果select查询出来再update行不通,所以先将图片从库里导到本地,然后在从本地拿数据进行更新操作,根据ImgID进行update操作 ; jdbc参数放到db.properties里(有工具类) WEB方式未实现,后期自行研究(可...
db2驱动jar包,附官网下载方式。jdk1.8版本可用的db2驱动。
DB9/DB15/DB25/DB37/DB50/DB62/DB78封装PDF
DB9 DB15 DB25 DB37 DB50 ...包括90个DB9~50接插件全系列封装文件,孔型、针型、直型,90度弯型,DB9/M,DB9/F,DB15/M,DB15/F,DB25/M,DB25/F,DB37/M,DB37/F,DB50/M,DB50/F等,可以直接应用到你的项目开发。
2》修改db1.clp脚本,首先找到 TAKEN AT 20071213133623 这一行,把下一行的两个"--"去掉,这样告诉恢复程序恢复数据到那个磁盘上,并且修改随后的盘符为在第3步中虚拟磁盘的盘符。 3》查找并替换所有 D:\data\DB1_...
亲测好用,挺不错的资源,大家快来下载吧!挺有用的!需要的话可以来下载哦!Microsoft.ACE.OLEDB.12.0驱动下载,解决 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序,权限问题
压缩包为适用于 Winddows的DB2版本 V11.1的数据库,博主大费周折找了好久才找到的,得来不易,且下且珍惜。
arcgis查看db包的照片
利用Oci将数据库中的图片取出来,并保存到本地
DB116952017工程资料名称分类及归档保存表.pdf
用于连接db2数据库的驱动,