可以使用prepareStatement操作blob数据(二进制数据)
插入数据库
FileInputStream fis = new FileInputStream("a.jpg"); ps.setBlob(4,fis);
读取blob
Blob photo = rs.getBlob("photo"); InputStream bis = photo.getBinaryStream(); FileOutputStream fos = new FileOutputStream("a.jpg"); byte[] buf = new byte[1024]; int len=0; while ((len=bis.read(buf))!=-1){ fos.write(buf,0,len); }