jdbc操作oracle的blob
由于thin驱动对setBinaryStream支持很差,没办法,只有采用笨点的方法了connOracle = JDBCDataSource.getJDBCDataSource("jdbc.informix").getConnection();connOracle.setAutoCommit(false);BLOB blob = null;PreparedStatement pstmt = connOracle.prepareStatement("update ygjbxx set jbxx_photo=empty_blob() where jbxx_bh='"+ ygdh + "'");pstmt.executeUpdate();pstmt.close();PreparedStatement pstmt1 = connOracle.prepareStatement("select jbxx_photo from ygjbxx where jbxx_bh= ? for update");//for update必须要加pstmt1.setString(1, ygdh);ResultSet rset = pstmt1.executeQuery();if (rset.next()) {blob = (BLOB) rset.getBlob(1);}pstmt1.close();OutputStream out1 = blob.getBinaryOutputStream();int i = 0;while ((i = in.read()) != -1) {//InputStream为方法的参数out1.write(i);}out1.flush();out1.close();PreparedStatement pstmt2 = connOracle.prepareStatement("update ygjbxx set jbxx_photo=? where jbxx_bh='"+ ygdh + "'");pstmt2.setBlob(1, blob);pstmt2.executeUpdate();pstmt2.close();connOracle.commit();
页:
[1]