0 Replies Latest reply on Jan 2, 2015 10:39 PM by 676039

    OTN BLOB Sample doesn't work for me.. still can't write BLOB into database


      Dear all,

      I am trying to write an image into a BLOB column in my table. I have read LOB Sample at OTN (http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html), but it doesn't work for me. I still can't write the image. Here is my code:

      lCnFetch = new UTIL_CONN().fnGetConnection(); if(lCnFetch == null) throw new UTIL_EXCEPTION("NoDataBase Connection","1500"); lCnFetch.setAutoCommit(false); PreparedStatement ps = lCnFetch.prepareStatement("INSERT INTO CLHS_BLOB VALUES('40056200800027', '3b', to_date('2008-12-16', 'yyyy-mm-dd'), '', 'novan2', EMPTY_BLOB(), 'foto novan2', '00961')"); File nmFile = new File("C:/novan.jpg"); ps.execute(); Statement stmt = lCnFetch.createStatement(); ResultSet rs = stmt.executeQuery("SELECT IMG FROM CLHS_BLOB WHERE TITLE = 'novan2' FOR UPDATE"); if (rs.next()) { Blob mapBlob = rs.getBlob(1); OutputStream blobOutputStream = ((oracle.sql.BLOB)mapBlob).getBinaryOutputStream(); InputStream sampleFileStream = new FileInputStream(nmFile); byte[] buffer = new byte[1000 * 1024]; int nread = 0; while( (nread= sampleFileStream.read(buffer)) != -1 )         blobOutputStream.write(buffer, 0, nread);        sampleFileStream.close(); blobOutputStream.close(); }

      And this was what I got:

      E WLTC0033E: Resource jdbc/ECHMS_LOCAL rolled back in cleanup of unresolved LocalTransactionContainment.
      E WLTC0032E: One or more resources rolled back. An unresolved LocalTransactionContainment had an unresolved action of rollback.
      E SRVE0026E: [Servlet Error]-[LocalTransaction rolled-back due to setRollbackOnly]: com.ibm.ws.LocalTransaction.RolledbackException

      Could anyone explain me about this?
      Thank you for any help.

      Novan A