my dog learned polymorphism*
The moose likes JDBC and the fly likes null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "null pointer exception" Watch "null pointer exception" New topic
Author

null pointer exception

kelly devon
Ranch Hand

Joined: Apr 15, 2004
Posts: 75
hi,
i sent info that i got from my form on the gui
to my db using this instruction
rs.executeQuery = "INSERT INTO Borrow VALUES("+"name", "id")");
when i do the above it gives me a null pointer exception
what am i doing wrong pls help


kel
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That line doesn't look right. I'd expect it to look like this:

if you are using a Statement (which it looks like you might be trying to do, since you are not binding any parameters). So, given how you've written it I don't see how you can get this to compile, unless I'm missunderstanding whasst you are trying to do.
[ September 23, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
kelly devon
Ranch Hand

Joined: Apr 15, 2004
Posts: 75
Originally posted by kelly devon:
hi,
i sent info that i got from my form on the gui
to my db using this instruction
rs.executeQuery = "INSERT INTO Borrow VALUES("+"name", "id")");
when i do the above it gives me a null pointer exception
what am i doing wrong pls help








sorry my mistake its
rs = stmt.executeQuery("INSERT INTO Borrow VALUES("+"name","+"id")");
[ September 23, 2004: Message edited by: kelly devon ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

try this

rs = stmt.executeQuery("INSERT INTO Borrow VALUES('" + name "',' " + id + "')");

I hope name and id both are char field
and both are your variables having value of name id


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Correction in previous line

rs = stmt.executeQuery("INSERT INTO Borrow VALUES('" + name + "',' " + id + "')");
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK - well the only place in that line a NullPointerException can be thrown is where a method is called on the Statement object:

I assume the Statement is null.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: null pointer exception
 
Similar Threads
I want full stacktrace and not ... 25 more
java haiku
SCJP Brainteaser (2)
Tomcat JAAS Authentication NullPointerException
How to play audio using this code in Grid View