Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet NullPointerException problem

 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic