File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes NullPointerException at oracle.sql.BLOB.createTemporary( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "NullPointerException at oracle.sql.BLOB.createTemporary( " Watch "NullPointerException at oracle.sql.BLOB.createTemporary( " New topic

NullPointerException at oracle.sql.BLOB.createTemporary(

Nick Moo

Joined: Oct 23, 2013
Posts: 3

I got NullPointerException at oracle.sql.BLOB.createTemporary( .
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);;
OutputStream writer = blob.getBinaryOutputStream();

return blob;

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

BLOB blob = getBlob(compressedClaim,connStore);
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(
> at oracle.jdbc.driver.T2CConnection.checkError(
> at oracle.jdbc.driver.T2CConnection.createTemporaryBlob(
> at oracle.sql.BLOB.createTemporary(

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Nick Moo

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);

Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

I am not sure but is this will help you
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

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

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:
subject: NullPointerException at oracle.sql.BLOB.createTemporary(
It's not a secret anymore!