io

public void getChaRu()throws Exception{
Connection conn = this.getConnection();
String sql = "";
PreparedStatement ps = null;

InputStream is = null;
OutputStream os = null;
try {
//数据库的读出与写入,blob类型
ResultSet rs = this.query("select facefile from t_wepec_user where SYSID = '894854044'");
while (rs.next()){
Blob blob = rs.getBlob(1);
is = blob.getBinaryStream();
ps.clearBatch();
os = new FileOutputStream("D:\\img\\dd"+ new Random().nextInt(9)+".jpg");
byte[] b = new byte[1024];
int i = 0;
while ((i = is.read(b))!= -1){
os.write(b,0,i);
}
sql = "update t_WEPEC_USER SET FACEFILE=? WHERE sysid = '884075058'";
ps = conn.prepareStatement(sql);
ps.setBinaryStream(1,is,is.available());
int a = ps.executeUpdate();
}

//本地写数据库,存的是blob类型
// FileInputStream fis = new FileInputStream("D:\\img\\yy.jpg");
// ps = conn.prepareStatement(sql);
// sql = "update t_WEPEC_USER SET FACEFILE=? WHERE sysid = '892206194'";
// ps.setBinaryStream(1,fis,fis.available());
// int i = ps.executeUpdate();
// logger.info(i);

//本地读入,写出
// os = new FileOutputStream("D:\\img\\gg.jpg");
// byte[] b = new byte[1024];
// int i = 0;
// while ((i = is.read(b))!= -1){
// os.write(b,0,i);
// }
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(is == null){
is.close();
}
if(os == null){
os.close();
}

} catch (IOException e) {
e.printStackTrace();
}
}
}
posted @ 2022-01-28 17:10  年少有时  阅读(46)  评论(0)    收藏  举报