Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Prepared statement returning a null value

843854Dec 19 2001 — edited Dec 21 2001
Hi,

I am having the following problem while using JDBC PreparedStatements.

I am trying to execute a query and fetch values in a result set. I am trying to fetch a string and date value. For the first row the date value is null and for the second row it is non null. But after returning the first null value, the resultset still gives me a null for the next non-null date.

This is what I read on the web regarding something similar:

When re-executing a previously created Prepared statement, the statement is not re-prepared. On an initial execute, a NULL is bound as a SQLT_STR (string) type, so a subsequent execute replacing it with a float (or anything non-string) requires a re-prepare.

I tried the following:

I wrote a customized result set (MyResultSet) that wraps the java result set object. It provides wrappers for the getString and getDate method. While fetching the values i made a check using wasNull() to find it the value was a null. Whenever the value was null i notified a registered listener. The listener took care to re prepare the statement.

Output: It works

Drawbacks:
1. Overhead of checking for wasNull everytime. Not very efficient.
2. Need to register listener that take care of re preparing the statement.

There needs to be a more efficient way of doing this since my program would be dealing with millions of records. I tried many options like clearing parameters, fetching warnings, closing result set etc but nothing seems to work.

Is there a better solution?

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2002
Added on Dec 19 2001
3 comments
697 views