If  (s != null) is true then s is already a String since you have already
declared it to be a String. So why try and convert it again to string in
'rs.getObject(i).toString()'
Also, you are getting the same result twice which will cause your
SQLException error. On the 2nd line you are getting rs.getString(i) or
rs.getString(1); On the 4th line you are trying the same result in
'rs.getObject(i).toString()' which is still on loop (1). This may be cause
of your problem. There shouldn't be any need to convert to String in line4,
neither to getObject(i) again.


*Antonio*
;


----- Original Message -----
From: Deepak Patil <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 01, 1999 8:18 AM
Subject: Re: how to check whether a column value is null in a database tab
le


> Here is the code I am using but it gives SQLException : No Data Found
>
> for (int i=1; i<=numCols; i++) {
> String s = rs.getString(i);
> if ( s != null)
>         out.println("<td>"  + rs.getObject(i).toString()+"</td>");
> else
>         out.println("<td>NULL</td>");
> }
>
> I am using MSSQL-server and jsdk 2.1
> What's wrong in this ?
>
> Deepak
>
>
> >From: "Sonal Patni (CTS)" <[EMAIL PROTECTED]>
> >Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> >        Servlet API Technology." <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: how to check whether a column value is null in a database
tab
> >             le
> >Date: Fri, 1 Oct 1999 15:14:17 +0530
> >
> >probably what u r doing is str.equals(null) which is bound to give a null
> >pointer exception
> >
> >instead of that should do (str==null)
> >
> >
> >-----Original Message-----
> >From: Deepak Patil [mailto:[EMAIL PROTECTED]]
> >Sent: Friday, October 01, 1999 1:09 AM
> >To: [EMAIL PROTECTED]
> >Subject: how to check whether a column value is null in a database table
> >
> >
> >Hi
> >I am using
> >rs.getString(1)
> >for getting a 1st columns value of a database table, I want to check
> >whether
> >the value is null or not, because if I use it without checking whether it
> >is
> >null or not it gives me a runtime NullPointerException....
> >
> >how can I check for nulity
> >
> >Deepak
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to