It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes nullpointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "nullpointer" Watch "nullpointer" New topic


kelly devon
Ranch Hand

Joined: Apr 15, 2004
Posts: 77
i am trying to send info to the database from my form gui
but i keep on getting a nullpointer exception from where i
use my statement to send this info
heres what i mean
stmt.executeQuery("INSERT INTO Borrow"+"VALUES("+name+","+age+")");
pls help me out and instead of Query i tried replacing with Update same null pointer
pls help wat im i doing wrong?

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Check whether your are getting the connection to the DB ..


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Its more likely the statement object ("stmt") is null. How do you create the Statement object?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
check your statement object, as Paul said. And yes, please give a space between your table_name and "VALUES" keyword.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32822

You are correct that you need to use executeUpdate. Also, as name is a string, it needs single quotes. You might consider using a prepared statement to avoid these formatting issues.

This isn't the source of your problem, but it is something you will hit later.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: nullpointer
It's not a secret anymore!