File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes sql Date, and getting Primary Key! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "sql Date, and getting Primary Key!" Watch "sql Date, and getting Primary Key!" New topic
Author

sql Date, and getting Primary Key!

Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
2 Questions!

1) If I try and send a timestamp to an SqlServer database, where I want the timestamp to be millisecond perfect, how does one achieve this? The following code

oh so helpfully strips the hours, mins and seconds off the time, and as the setHour()/setMinute()/setSecond() methods are all depricated, i feel like strangling someone. Any ideas?

2)Is there anyway to execute an insert into a database and while doing so retrieve the newly created primary key. It would save two databse trips per insert. I've tried using the preparedStatement.execute() method, but no result set is returned, unsurprisingly.

Many thanks
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
1) That's what the spec says a java.sql.Date is supposed to do:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html

perhaps a java.sql.Timestamp will do what you want.
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html

2)See Statement.getGeneratedKeys()
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: sql Date, and getting Primary Key!
 
Similar Threads
Auto Increment ID Field Table in the Oracle Database
save Date() into mysql Timestamp
Funny number --- oracle sequence + Hibernate
Date format
Recommendation on design approach