• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer exception in con.createStatement();

 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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->

 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to be precise the error is at line number 31
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a Struts issue; moving to... JDBC?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have to use the following directly or some settings have to be made
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The old org.gjt... driver is still provided--it's the same driver.
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i am getting this error

Access denied for user 'mysql'@'localhost' (using password: YES)
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Looks like there is some problem with your mysql password or username.....
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everybody , i installed mysql again and set the username and password to root.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic