public void saveBlob(String path) throws SQLException, FileNotFoundException, IOException { //ITRDR_environment.xlsx PreparedStatement pstmt= connection.prepareStatement("update blob_FILE set file =?where id =123456");
InputStream is = new FileInputStream(path+"22.xlsx"); pstmt.setBinaryStream(1, is,is.available()); pstmt.executeUpdate(); connection.commit(); is.close(); } public void getBlob(String path) throws SQLException, FileNotFoundException, IOException { String query = "SELECT FILE FROM blob_FILE where id =123456"; java.sql.Blob blob= null; preparedStatement = connection.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { blob = resultSet.getBlob("FILE"); } InputStream ins= blob.getBinaryStream(); OutputStream ops = new FileOutputStream(new File(path+"11.xls")); byte[]b = new byte[1024]; int len = 0; while((len=ins.read(b))!=-1) { ops.write(b, 0, len); } ops.close(); ins.close(); }