Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nullpointer

 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check whether your are getting the connection to the DB ..

Srini
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its more likely the statement object ("stmt") is null. How do you create the Statement object?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kelly,
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic