//将图片输入到数据库中 // String sql="insert into t_user2 (username,headImg) values (?,?)"; // ps=conn.prepareStatement(sql); // ps.setObject(1, 2); // ps.setBlob(2, new FileInputStream("d:/img.png")); // ps.execute(); //读取图片到程序中再转出去 String sql="select * from t_user2 where id=?"; ps=conn.prepareStatement(sql); ps.setObject(1, 3); rs=ps.executeQuery(); while(rs.next()) { Blob b=rs.getBlob("headImg"); is=b.getBinaryStream(); byte[] temp=new byte[1024*10]; int len; os=new FileOutputStream("d:/imgcopy"); while((len=is.read(temp))!=-1){ os.write(temp, 0, len); }
原文:https://www.cnblogs.com/code-fun/p/11443674.html