This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590) " Watch "NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590) " New topic
Author

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

Nick Moo
Greenhorn

Joined: Oct 23, 2013
Posts: 3
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

Joined: May 26, 2003
Posts: 30789
    
157

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nick Moo
Greenhorn

Joined: Oct 23, 2013
Posts: 3
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

Joined: Apr 12, 2009
Posts: 449

I am not sure but is this will help you


http://muhammadkhojaye.blogspot.com/
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Oct 23, 2013
Posts: 3
Thanks for your help, Martin and Muhammad. These suggestions are helpful. I'm changing the code and testing now.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590)