• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException in PreparedStatement...

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Things looking weird in Java, Yes, Ofcourse when i run this code yesterday it works fine and now it shows me a NPE on the PreparedStatement line.. Here is my code...

: Edited :
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So "con" is null. Where is is set?
[ July 23, 2008: Message edited by: Paul Sturrock ]
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The con is set in dbmodel.java and i extends that file with this file inorder to access the DB methods such as Statement, PS and con etc....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and how/when is it set? Something is going wrong with how you use it. Either there has been a problem establishing a connection (are there any stacktraces?) or you are using it incorrectly (e.g. there is an open connection step you are missing).
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the stackTrace of errors...



 
vedha vas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajkumar balakrishnan,

The problem is with the con.Con is null.
The connection is not estabilished thats why its throwing NPE.
Pl post the dbModel.java class also so that we can find out how you are estabilishing the connection.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that is your NullPointerException. Well, we already know what causes that: the variable "con" is null. If there are no other exception messages then we can assume you are doing something wrong how you use con. Can you show use the code where con is initialised?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Insert this line just before it:
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I had this page open for some time, and didn't realise you had so many useful replies before mine! Sorry.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
: Edited :
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So presumably you have actually called your connect() method before you call your failing method?
 
vedha vas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajkumar balakrishnan ,

In the checkSession method, in the try part first call the valueBound(event) method after that start
with the code:
ps=con.prepareStatement(SQL2);
ps.setString(1,sname);
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Small mistake.....
Thanks for your reply....
Its the closing time for this thread...
Meet you in some other post...

Thanks for all ranchers....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vedha vas:
Hi Rajkumar balakrishnan ,

In the checkSession method, in the try part first call the valueBound(event) method after that start
with the code:
ps=con.prepareStatement(SQL2);
ps.setString(1,sname);


You should not be calling these methods directly. DBModel implements HttpSessionBindingEvent so will be called when a session binding event occurs. Presumably the pattern is to open a single connection for a single user when their session is bound?
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.... Ofcourse....Thats's right...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic