aspose file tools*
The moose likes JDBC and the fly likes PreparedStatement and sysdate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement and sysdate" Watch "PreparedStatement and sysdate" New topic
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: 30294
    
150

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement and sysdate