Forums Register Login

Null pointer exception in con.createStatement(); (Struts 2 using netbeans6.1 and MYSQL)

+Pie Number of slices to send: Send
i am creating a application in struts2 using netbeans 6.1. I have done database connection with MYSQL from netbeans. It also shows connection successful , but gives null pointer exception on this line -> con.createStatement();

Log is as folllows->

java.lang.NullPointerException
at net.roseindia.Login.execute(Login.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly
+Pie Number of slices to send: Send
hi,

then con is null.

how do you initialize this variable con? (post some code)

Herman
+Pie Number of slices to send: Send
i have pasted the code below , it shows null pointer exception on the line indicated as ##.

+Pie Number of slices to send: Send
hi,

my guess is that

throws a ClassNotFoundException


might be in your log, but it's only 1 line, easy to overlook.

Why not change it into


Good luck!

Herman
PS Please copy/paste from your log if you reply.
+Pie Number of slices to send: Send


for the above code i got the following error in the log...how to get around it

+Pie Number of slices to send: Send
hi,

if the e.getMessage() does not give enough information, add the class of the exception


It will probably give you a ClassNotFoundException, here's how to solve it:

If you have a connection from Netbeans to your MySQL database, that does not mean that your application can connect to the MySQL database.
You will have to add the mysql driver (the .jar file that it's in) to your webapplication (just put the jar file the lib folder of your webapplication), or add that .jar file to the classpath of your server.

Herman
+Pie Number of slices to send: Send
Thanks herman...now i am able to connect to MYSQL
The only cure for that is hours of television radiation. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7814 times.
Similar Threads
Setting up a database connection with Struts 2 and Tomcat 6.0
Null pointer exception in con.createStatement();
Struts2: Servlet.service() NullPointer
from struts 2.0. to 2.1 - tokenSession
making hibernate query [select] using null value
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:42:09.