Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes setNull(1, java.sql.Types.DATE) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "setNull(1, java.sql.Types.DATE)" Watch "setNull(1, java.sql.Types.DATE)" New topic

setNull(1, java.sql.Types.DATE)

Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
If I use setNull(1, java.sql.Types.DATE); function, it will insert null on my table's column.
I want to select the date from another table and insert into my table's column, what should I do?
I am sure I cannot call setNull(1,java.sql.Types.DATE), it will insert NULL in my column.

Thanks in advance.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2551

You can use setDate() or setTimestamp().

OCUP UML fundamental and ITIL foundation
Kee Kee moon
Ranch Hand

Joined: Dec 11, 2009
Posts: 147
Jan Cumps wrote:You can use setDate() or setTimestamp().

Would you please give me some examples how to use setDate or setTimestamp(). I have been working on setDate() but failed.
I got errors.

Sorry for the double post on the Java General forum.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19758

You don't describe how you failed. It would definitely help if you provided some explanation.

However I will take a guess: you don't understand that the setDate() method requires a java.sql.Date object and not a java.util.Date object, and you don't know how to get one of those. You said you were getting a date from some other table? Then the getDate() method returns you a java.sql.Date object which you can use.
I agree. Here's the link:
subject: setNull(1, java.sql.Types.DATE)
It's not a secret anymore!