Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NULL pointer exception.

 
sunil khandelwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am very new to servlet.

I made a class to connect servlet to database bt i m getting this error.




my servlet class GetData.java is:-


and my database connection class Mysql_connection.java code is :-


please tell me solution ASAP


Thanks in advance.>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me solution ASAP

Please EaseUp and UseRealWords.
 
sunil khandelwal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k.

ya next time i will do.

by ASAP my means as soon as possible.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not initialize Connection object, that's why you are receiving a NullPointerException

I can't see any call to the method that initializes the Connection object.



Call method connection before calling the method query
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:I can't see any call to the method that initializes the Connection object.

Line 36
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your connection url and parameters valid?
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 36...Great. Now i see it
 
Steven Schwab
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In lines 35-43 of GetData, you're catching any exceptions that DriverManager.getConnection() might be throwing and just printing out stack traces.

If DriverManager.getConnection() throws an exception (and you ignore it like you are now), then Mysql_connection.connection will still be null when you try to use it in query().

Are any stack traces being printed out to the console or the log files?
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your exception catching process is not giving you the enough information about exactly where the problem is.
every where you have used throws clause
i think first catch the exception using the try/catch block and then throw the same exception in the catch block
for example:



this will give you great advantages like debugging at development time.


Please correct me if i am wrong at any place(in this concept).
 
Md Haidar Ali Khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:
please tell me solution ASAP

Please EaseUp and UseRealWords.

Dear
you check out your connection Object. Might be that no connect propery.
Regards,
MD. Haidar Ali Khan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic