• Post Reply Bookmark Topic Watch Topic
  • New Topic

sql Date, and getting Primary Key!  RSS feed

 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!