NullPointerException when executing PreparedStatement on Oracle DB to insert Blob NullPointerException when executing PreparedStatement on Oracle DB to insert Blob oracle oracle

NullPointerException when executing PreparedStatement on Oracle DB to insert Blob


In my app I used a File instead of a Blob for the method input and have done the BLOB insert this way:

public void insertBlob(String filedesc, File file) {    Connection con = DriverManager.getConnection(url, username, password);    InputStream input = new FileInputStream(file);    PreparedStatement pstmt = con.prepareStatement(        "insert into schema.table values(?,?)");    pstmt.setString(1, filedesc);    pstmt.setBinaryStream(2, input);    pstmt.execute();}

Maybe you will need some try-catch, but I hope this will help You.


Try using the *createTemporary(yourConnection, false, oracle.sql.BLOB.DURATION_CALL)* function on the oracle.sql.BLOB to create your instance. After that just use the setBytes(...) to set its content.


One remark: prepStmt.setDate(2, erzeugung); is simpler.

I would have expected a simple:

InputStream blobIS = pdf.getBinaryStream();prepStmt.setBlob(4, blobIS, pdf.length());... pdf.free();