• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590)

 
Nick Moo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590) .
Not sure whether my BLOB creation is ok or not. Thanks a lot for any help!

Here is the coding that creates a BLOB.

private BLOB getBlob(byte[] str, Connection con) throws SQLException, IOException {

BLOB blob = BLOB.createTemporary(con, true, BLOB.DURATION_SESSION);
blob.open(BLOB.MODE_READWRITE);
OutputStream writer = blob.getBinaryOutputStream();
writer.write(str);
writer.flush();
writer.close();
blob.close();

return blob;
}

After inserting this BLOB into database table via ojdbc, BLOB.freeTemporary() is called.

BLOB blob = getBlob(compressedClaim,connStore);
rsImagePstmt.setObject(4,blob);
rsImagePstmt.executeUpdate();
BLOB.freeTemporary( blob );

Sometimes it's running ok and finished properly. Sometimes I got the following exception after running 2.5 hours.

Thanks a lot for any suggestion and help. We use oracle 10.2 and jdk1.4 library here.

> Exception: java.lang.NullPointerException
> at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:669)
> at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:602)
> at oracle.jdbc.driver.T2CConnection.createTemporaryBlob(T2CConnection.java:2039)
> at oracle.sql.BLOB.createTemporary(BLOB.java:590)


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
378
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick,
Welcome to CodeRanch!

This isn't particularly helpful, but I always use the setBinaryStream() API on my BLOBs and not the Oracle specific APIs. As a debugging exercise, it might be useful to see if that API gives the problem too.
 
Nick Moo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jeanne,

Thanks a lot for your suggestion. Do you mean to do the following? If not, would you mind sharing your part of coding?
This is my first time to use BLOB. I really appreciate any help. Thanks again.

byte[] data = ...;

PreparedStatement ps = connection.prepareStatement(...);

ByteArrayInputStream stream = new ByteArrayInputStream(data);

ps.setBinaryStream(1, stream);

ps.executeUpdate();
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure but is this will help you
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you're still looking for a solution: there's an Oracle specific way to set/update BLOBs and CLOBs without using a temporary BLOB/CLOB. I've described it previously here and here. I'm using this method for a long time without any problems.

This will lead to an Oracle-specific code, of course.
 
Nick Moo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, Martin and Muhammad. These suggestions are helpful. I'm changing the code and testing now.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic