Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / March 2004

Tip: Looking for answers? Try searching our database.

wasNull() syntax

Thread view: 
Henry - 27 Mar 2004 00:35 GMT
I need some help with the syntax for properly calling the wasNull()
function in JSP.  (I'm using Win2K and Tomcat 5.0.19 with Oracle 8.1.5
and Mozilla 1.6 )

I have a table in which some records for a column may be null.  It is a
string datatype.  I'm calling a stored procedure which returns a
ResultSet.  While iterating through the ResultSet, I want to test this
column for null values so I can print several dashes "---" instead of
"null."  At the moment, I'm doing it like this:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

 while (objRecordSet.next()) {

   // ...

   if (objRecordSet.getString("exer_time").wasNull())
      out.println("<TD align='right'><FONT SIZE='-1' +
      name='Arial'>" + " --- " + "</FONT></TD>");
   else
      out.println("<TD align='right'><FONT SIZE='-1' +
      name='Arial'>" + objRecordSet.getString("exer_time") +
      "</FONT></TD>");

   \\ ...

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

This fails.  The error message in the browser is "cannot resolve
symbol."  I'm not at all sure that I'm using the function correctly, or
even, given the way my stored procedure is written, as the Java help
merely describes the function but provides no example;  it says:

     " Retrieves whether the last OUT parameter read had the value of
       SQL NULL."

The stored procedure I'm using does not use an OUT parameter, however:

PACKAGE SPEC
------------

FUNCTION getPushupRecs RETURN pushupResultSet;

PACKAGE BODY
------------

FUNCTION getPushupRecs RETURN pushupResultSet
IS

   pushup_cursor  pushupResultSet;

BEGIN

   OPEN pushup_cursor FOR
   SELECT *
   FROM   pushups
   ORDER BY exer_date, set_num;

   RETURN pushup_cursor;

END;

I'd be grateful if someone could point me in the right direction.

Henry
Luke Webber - 27 Mar 2004 03:23 GMT
> I need some help with the syntax for properly calling the wasNull()
> function in JSP.  (I'm using Win2K and Tomcat 5.0.19 with Oracle 8.1.5
[quoted text clipped - 13 lines]
>
>     if (objRecordSet.getString("exer_time").wasNull())
[snip]

You're calling wasNull() on the String value returned rather than on the
ResultSet. Instead, try something like this...

   String exerTime = objRecordSet.getString("exer_time");
   if (objRecordSet.wasNull())
       ...

Luke
Henry - 27 Mar 2004 02:33 GMT
Thanks, Luke.

I was suspecting that such was the case.  What I really want to do is
test for nulls in particular fields.  I'll have a few more stabs at it
before I start looking for alternative solutions.

Henry

>>I need some help with the syntax for properly calling the wasNull()
>>function in JSP.  (I'm using Win2K and Tomcat 5.0.19 with Oracle 8.1.5
[quoted text clipped - 24 lines]
>
> Luke
Luke Webber - 27 Mar 2004 06:24 GMT
> Thanks, Luke.
>
> I was suspecting that such was the case.  What I really want to do is
> test for nulls in particular fields.  I'll have a few more stabs at it
> before I start looking for alternative solutions.

The code I posted *will* test for null on a particular column - the last
column referenced. OTOH, it would be easier just to test the returned String
value, because that will be null if the column is null. That's what I would
do in this situation. But that doesn't work for getInt or getLong, which
both return zero on null columns.

Luke
Henry - 27 Mar 2004 10:11 GMT
Cannot resolve symbol?  Sure- since I was using "NULL" instead of
"null."   The following does the job:

     if(objRecordSet.getString("exer_time") == null)
        out.println("<TD align='right'><FONT SIZE='-1' name='Arial'>" +
        "-----" + "</FONT></TD>");
     else
        out.println("<TD align='right'><FONT SIZE='-1' name='Arial'>" +
        objRecordSet.getString("exer_time") + "</FONT></TD>");

Chalk this up to an ODM malfunction - Oh Dopey Me.

Henry

>>Thanks, Luke.
>>
[quoted text clipped - 9 lines]
>
> Luke


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.