| Author |
NULL pointer exception.
|
sunil khandelwal
Greenhorn
Joined: Aug 02, 2010
Posts: 5
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
please tell me solution ASAP
Please EaseUp and UseRealWords.
|
[My Blog]
All roads lead to JavaRanch
|
 |
sunil khandelwal
Greenhorn
Joined: Aug 02, 2010
Posts: 5
|
|
k.
ya next time i will do.
by ASAP my means as soon as possible.
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
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
|
Bye,
Nicola
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Nicola Garofalo wrote:I can't see any call to the method that initializes the Connection object.
Line 36
|
 |
Ananth Chellathurai
Ranch Hand
Joined: Nov 21, 2007
Posts: 348
|
|
|
Is your connection url and parameters valid?
|
Ananth Chellathurai [Walk on software]
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
Line 36...Great. Now i see it
|
 |
Steven Schwab
Greenhorn
Joined: May 25, 2010
Posts: 9
|
|
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
Joined: Jul 14, 2010
Posts: 63
|
|
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).
|
Subhash Kumar
Attitude is everything
|
 |
Md Haidar Ali Khan
Greenhorn
Joined: Feb 18, 2010
Posts: 12
|
|
Dear
you check out your connection Object. Might be that no connect propery.
Regards,
MD. Haidar Ali Khan
|
 |
 |
|
|
subject: NULL pointer exception.
|
|
|