• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

NullPointerException in PreparedStatement...

 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the stackTrace of errors...



 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 72466
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Insert this line just before it:
 
Campbell Ritchie
Marshal
Posts: 72466
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
: Edited :
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.... Ofcourse....Thats's right...
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic