This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes using setNull correctly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "using setNull correctly" Watch "using setNull correctly" New topic
Author

using setNull correctly

Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I am trying to figure out the correct way to use setNull in a prepared statement.

I.E.
ps.setNull(1, Types.INTEGER); // Set my first column to null, it is an int

I currently do not have access to the type so i would like to know if this is ok:
ps.setNull(1, Types.NULL); // Sorry don't know column 1's type

I have read a few places that Types.NULL is ok in all situations but I don't believe it.

Any experts in the area.

This relates to a post I also just put up in trying to figure out what the type is from the column name. I.E. since I don't know the type is there an easy way to get it from the column name?

Thanks!
Billy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using setNull correctly
 
Similar Threads
commit problem - always happens even if set to false!!
save Date() into mysql Timestamp
Getting strange exception while executing preparedStatement.
how can i insert a null value in a table
SetNull() in a select PreparedStatement