Forums Register Login

Null pointer exception in con.createStatement();

+Pie Number of slices to send: Send
i am getting null pointer exception at the following line
stmt = con.createStatement();
int val = stmt.executeUpdate("INSERT INTO WEBDB.HNM VALUES('1','hRISHIKESH')");

my code is as follows->

+Pie Number of slices to send: Send
to be precise the error is at line number 31
+Pie Number of slices to send: Send
Not a Struts issue; moving to... JDBC?
+Pie Number of slices to send: Send
There are several issues with this code, aside from looking like it was written 10 years ago :(

You're obviously not getting a connection when you think you are--any log messages? Is logging turned on at the DEBUG level?
+Pie Number of slices to send: Send
Hint: you load the driver in the scope of a try block. You try to reuse it outside the scope of the try block.
What happens if you move line 31 and associated lines inside the try?
+Pie Number of slices to send: Send
Can you post the full stack trace ? Apart from the driver name (I'm not sure about that driver class you have used) that code should work as it did for me.
+Pie Number of slices to send: Send
we have to use the following directly or some settings have to be made
+Pie Number of slices to send: Send
 

Hrishikesh Maluskar wrote:we have to use the following directly or some settings have to be made


It's apparent that you are using a different driver. I think you should check the documentation of that to see how to connect. For mysql's driver this works fine.
+Pie Number of slices to send: Send
The old org.gjt... driver is still provided--it's the same driver.
+Pie Number of slices to send: Send
now i am getting this error

Access denied for user 'mysql'@'localhost' (using password: YES)
+Pie Number of slices to send: Send
Hi,

Looks like there is some problem with your mysql password or username.....
+Pie Number of slices to send: Send
thanks everybody , i installed mysql again and set the username and password to root.
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 10724 times.
Similar Threads
Struts 2 -Eclipse
Struts 2 "package com.opensymphony.xwork2" does not exist
Struts 2- Database Connectivity
Null pointer exception in con.createStatement(); (Struts 2 using netbeans6.1 and MYSQL)
Problem with the "where" query.
More...

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