File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes ResultSet NullPointerException problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ResultSet NullPointerException problem" Watch "ResultSet NullPointerException problem" New topic
Author

ResultSet NullPointerException problem

Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
I'm having difficulties with accessing a MySQL database resultset in a JSP.
The error I'm getting is this:
The following JDBC exception has occurred : java.lang.NullPointerException
The reason I get it is because some columns in the database can be null and then the "ResultSet resultset.getString(4).trim();" code produces this error.
I've been over the java.sql class docs to see if I cound find a boolean to indicate whether or not a column was null but I couldn't find anything.
Ideas?
Thanks,
Terry


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
Originally posted by Terence Doyle:
HI,
I'm having difficulties with accessing a MySQL database resultset in a JSP.
The error I'm getting is this:
The following JDBC exception has occurred : java.lang.NullPointerException
The reason I get it is because some columns in the database can be null and then the "ResultSet resultset.getString(4).trim();" code produces this error.
I've been over the java.sql class docs to see if I cound find a boolean to indicate whether or not a column was null but I couldn't find anything.
Ideas?
Thanks,
Terry

Try using :
String s = resultset.getString(4);
if(s!=null){
s = s.trim();
}

Shilpa.
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
sure you're not missing
ResultSet rs;
rs.next();
if you don't issue this first time u want to access the result set you will get the null pointer exception
------------------
KaReEm


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
Thanks guys.
The null test was the trick!
I didn't realise the trim() method threw an exception id the String passed in was null.
Bye,
Terry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet NullPointerException problem
 
Similar Threads
Newbie problem. JDBC Error
Problem in Seperating Core Servlet to Database Query Java
ResultSet is null
Returning ResultSet
cannot find symbol