public static void printpic(){
String sql="select id,name,photo from xuan_student ";
try {
Connection conn=ConnectionUtils.openConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
FileOutputStream fos=new FileOutputStream(new File("asd.jpg"));
InputStream ins=rs.getBinaryStream("photo");
byte[] buffer=new byte[4*1024];
int length=0;
while((length=ins.read(buffer))!=-1){
fos.write(buffer,0,length);
}
}
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
jdbc中读取图片文件
最新推荐文章于 2023-01-03 17:30:52 发布