| Author |
PreparedStatement and sysdate
|
Lukas Alamar
Ranch Hand
Joined: Mar 17, 2004
Posts: 68
|
|
hi all, i'm trying to make an insert into an oracle db table and i need to use the db system date: String query = insert into myTable (my_date) values (?); PreparedStatement ps = con.prepareStatement(query); //insert code here to bind the variable in the prep stat ps.executeUpdate; if i wasn't using a prep stat i'd simply write "insert into myTable (my_date) values (sysdate)", but i have (for some reasons) to use the prep stat...can i still use the db system date??? what i DO NOT want to do is this: ps.setTimestamp(new Timestamp(System.currenttimeMillis())); can you please enlighten me on this?? thanx [ April 22, 2004: Message edited by: Lukas Alamar ]
|
SCJP 1.4
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
if i wasn't using a prep stat i'd simply write "insert into myTable (my_date) values (sysdate)", but i have (for some reasons) to use the prep stat...can i still use the db system date???
Did you try it? (Why not?) If you like to use a '?', try: pQuery = "INSERT INTO myTable (my_date) \ VALUES (SELECT sysdate FROM dual WHERE 1 = ?)"; but I can imagine you may use the simple above statement.
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
Jason Steele
Ranch Hand
Joined: Apr 25, 2003
Posts: 100
|
|
you do not need to use a prepared statement for an Oracle internal function like sysdate.
String query = insert into myTable (my_date) values (?); PreparedStatement ps = con.prepareStatement(query); //insert code here to bind the variable in the prep stat ps.executeUpdate;
That preparedStatement is waiting for a parameter. You could use: But then you might as well just forget the prepared statement...unless this is something happening often.
|
An egg is a chicken's house!
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
|
|
Why don't you want to do it this way? ps.setTimestamp(1, new Timestamp(System.currenttimeMillis()));
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: PreparedStatement and sysdate
|
|
|