• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql Date, and getting Primary Key!

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic