Using CallableStatement.wasNull() after getObject()

In our aplpication we are returning ResultSets from PL/SQL functions. We use CallableStatement.getObject()
to return the ResultSet. After calling getObject we call wasNull() to make sure
we did receive something.
Originally we were using the jcbd thin driver provided by Oracle and our code
ran fine. We had problems with that driver and switched to the OCI driver. The
OCI driver does not like our code calling wasNull after getObject(). It throws
and exception saying we have not called a getXXX method yet.
The specification is kind of vague on this, it says wasNull can be called after
any getXXX method. My question is, is there a problem with the OCI driver or
is or code wrong?
Below is a snippet of code that worked with the thin driver but not with the OCI
driver:
CallableStatement _stmt = null;
          int _arg = 1;
          try {
               stmt = connection.prepareCall(GET_OTHER_PERFORMANCE_ASSETS_STMT);
               stmt.registerOutParameter(arg++, sonymusic.util.JDBCHelper.SONYMUSIC_CURSOR);
               if (inSiteId == null) {
                    stmt.setNull(arg++, java.sql.Types.BIGINT);
               } else {
                    stmt.setLong(arg++, inSiteId.longValue());
               if (inPerformanceId == null) {
                    stmt.setNull(arg++, java.sql.Types.BIGINT);
               } else {
                    stmt.setLong(arg++, inPerformanceId.longValue());
               if (authUserIdIn == null) {
                    stmt.setNull(arg++, java.sql.Types.BIGINT);
               } else {
                    stmt.setLong(arg++, authUserIdIn.longValue());
               _stmt.execute();
               java.sql.ResultSet result = (java.sql.ResultSet)stmt.getObject(1);
               if (_stmt.wasNull())
                    return null;
               else
                    return _result;

Hi Jeff,
as mentioned in the spec, refereing to the doc you refered to earlier:
You should be able to get the resultset first and then read the param on the
resultset and then make a call to CallableStatement.wasNull to discover if
the read returned a SQL "NULL". (if this value read from the resultset is a
SQL "NULL" the wasNull() call will return a true).
Hope this answers your questions here and clears up any confusion with the
java null and, the SQL NULL that the wasNull call detects.
getObject() is basically returning you what you asked it to return when you
registered the out parameter.
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html
7.3.2 Retrieving NULL values as OUT parameters
As with ResultSets, in order to determine if a given OUT parameter value is
SQL "NULL" you must first read the parameter and then use the
CallableStatement.wasNull method to discover if the read returned a SQL
"NULL".
When you read a SQL "NULL" value using one of the CallableStatement.getXXX
methods, you will receive a value of null, zero, or false, following the
same rules specified in section 7.1.2 for the ResultSet.getXXX methods.
sree
"J Drost" <[email protected]> wrote in message
news:[email protected]...
>
I am comfortable with a getXXX on available returning an empty result setif the
pl/sql function itself returned an empty result set (if you do 'where 1 =0');
Just as I am comfortable with a getInt invocation returning a 0 if thepl/sql
function itself returned a 0. Or Course.
I do however expect to be able to check wasNull on the CallableStatementafter
getting a ResultSet from an out parameter. If the pl/sql function itselfdid
not return a result set (it is possible in Oracle to simply not return avalue
from a function), then I expect wasNull to return true.
I would imaging that it is open to discussion what the getXXX shouldreturn if
the database doesn't return anything. I would expect a null (after all Iam calling
getObject, and you wouldn't expect the driver any other kind of emptyobject,
so why an empty result set) but you could argue that an empty result setwould
be acceptable. Regardless of that argument; if a function didn't returnthe result
set, after the getXXX the wasNull should return true. Otherwise thedriver is
hiding the actual results of the database call.
Jeff
"Sree Bodapati" <[email protected]> wrote:
And I would like to add this note from 'Joe' here :
"an empty result set is still a result set, not a null.
Applications may well run queries that return no rows, but the
application
may still want the result set metadata, which is only available from
the resultset. In fact some applications purposely execute queries
with a clause like 'where 1 = 0' to ensure no rows are returned, but
guarantee that they get the metadata."
"Sree Bodapati" <[email protected]> wrote in message
news:[email protected]...
If you read through the same doc an little furture, They talk about
resultsets,
7.3.2 Retrieving NULL values as OUT parameters
As with ResultSets, in order to determine if a given OUT parametervalue
is
SQL "NULL" you must first read the parameter and then use the
CallableStatement.wasNull method to discover if the read returned aSQL
"NULL".
When you read a SQL "NULL" value using one of the
CallableStatement.getXXX
methods, you will receive a value of null, zero, or false, followingthe
same rules specified in section 7.1.2 for the ResultSet.getXXX methods.
hth
sree
"J Drost" <[email protected]> wrote in message
news:[email protected]...
Is their any explanation as to why a default value (an empty result
set)
is returned
without setting the wasNull flag? This behavior seems to be
inconsistent
with
the way other out parameters work. For example, when a function
that is
expected
to return a number doesn't return a value, the default value (zero)
is
returned
from the CallableStatement.getInt() method, but the wasNull flag
is set
to
true.
I don't know, it just doesn't seem consistent to me.
Also, you are saying that if I have a pl/sql function that returns
a
REFCURSOR
(a weakly typed cursor), and that function doesn't return a value,
then
the driver
is going to create a ResultSet for me that contains no rows and has
a
ResultSetMetaData
with a columnCount of zero? I would expect to get a java null based
on
what the
spec, as well as they way other parameter types work.
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html
7.1.2 Null result values
* A Java "null" value for those getXXX methods that return Javaobjects.
* A zero value for getByte, getShort, getInt, getLong, getFloat,and
getDouble
* A false value for getBoolean.
"Sree Bodapati" <[email protected]> wrote:
wasNull() checks to see if the last OUT param value is SQL NULL.
if
you
have a CURSOR (ResultSet equivalent) as the OUT param then it willnot
be
SQL NULL if no results are returned.
The Weblogic oci driver returns an empty resultset object in sucha
case.
I
dont think it sets the wasNull() to return true in such a scenario.
HTH
Sree
"Robert DeWilder" <robert@[email protected]> wrote in message
news:[email protected]...
In our aplpication we are returning ResultSets from PL/SQL
functions.
We
use CallableStatement.getObject()
to return the ResultSet. After calling getObject we call
wasNull()
to
make sure
we did receive something.
Originally we were using the jcbd thin driver provided by Oracle
and
our
code
ran fine. We had problems with that driver and switched to the
OCI
driver. The
OCI driver does not like our code calling wasNull after
getObject().
It
throws
and exception saying we have not called a getXXX method yet.
The specification is kind of vague on this, it says wasNull can
be
called
after
any getXXX method. My question is, is there a problem with the
OCI
driver
or
is or code wrong?
Below is a snippet of code that worked with the thin driver but
not
with
the OCI
driver:
CallableStatement _stmt = null;
int _arg = 1;
try {
_stmt =
connection.prepareCall(GETOTHER_PERFORMANCE_ASSETS_STMT);
stmt.registerOutParameter(arg++,sonymusic.util.JDBCHelper.SONYMUSIC_CURSOR);
if (inSiteId == null) {
stmt.setNull(arg++, java.sql.Types.BIGINT);
} else {
stmt.setLong(arg++, inSiteId.longValue());
if (inPerformanceId == null) {
stmt.setNull(arg++, java.sql.Types.BIGINT);
} else {
stmt.setLong(arg++, inPerformanceId.longValue());
if (authUserIdIn == null) {
stmt.setNull(arg++, java.sql.Types.BIGINT);
} else {
stmt.setLong(arg++, authUserIdIn.longValue());
_stmt.execute();
java.sql.ResultSet _result =
(java.sql.ResultSet)_stmt.getObject(1);
if (_stmt.wasNull())
return null;
else
return _result;

Similar Messages

Maybe you are looking for

  • Gradient swatch

    Hello. How is it I can make a gradient swatch with a 90º angle (for example) a saved swatch? Whenever I have saved a gradient swatch it does not allow me to specify (or save) the angle I would like the gradient to run. So whenever I create a shape an

  • Permissions not being propagated to files

    Hi. Wondering if anyone can help me. Iv recently updated to Mavericks & Server 3.0.2. Iv setup permissions on a shared folder using the server app. Works fine apart from files aren't getting the correct permissions. Instead they get a permission call

  • SMPP Gateway Integration

    HTTP API to submit messages on SMPP: http://<server>:<port>/bulksms/bulksms?username=XXXX&password=YYYYY&type=Y&dlr=Z&destination=QQQQQQQQQ&source=RRRR&message=SSSSSSSS<&url=KKKK> <server>: smpp1.kapsystem.com.com, smpp2.kapsystem.com, smpp3.kapsyste

  • BO Edge 3.1 Where is the SDK?

    Where can I find the sdk in BO Edge 3.1?  I have developed using the SDK a few years back and looking to integrate BO into my ASP.NET application again. Thanks Tom

  • Get Error message "Key not valid in this status" using Win 8 Pro.

    Hello Community, While I try to install the program i get the error message in the title. I downloaded it with t-online Homepage-plan. On both: Premiere Elements and Photoshop Elements 12. I using a 64bit based PC. Already tried: Running in XP-Mode S