• 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

java.sql getTimestamp

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a table with a column date that contains the date format like 2009-10-10 12:11:51.140

And I need to select the date as above 2009-10-10 12:11:51.140 and insert into another table. So here is my code, but I got errors
ORA-01847: day of month must be between 1 and last day of month

Stmt.setTimestamp(1, result.getTimestamp("date"));

Do I miss anything?
Thanks.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your column is dateTime and not timestamp, why bother with timestamp at all?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JDBC.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim McGuire wrote:If your column is dateTime and not timestamp, why bother with timestamp at all?



What should I do in order to get the dateTime 2009-10-10 12:11:51.140 inserted into another table?

Thanks
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should bear in mind that we don't know what your PreparedStatement looks like. And that we don't know anything about this table and what type of column you're trying to use. (Actually, not true: we know it's in an Oracle database.)

So absent that useful information I would suggest you try to insert it only in a column which is set up to receive timestamp information. And don't write SQL which tries to convert it to some other format; let the database driver take care of formatting.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:You should bear in mind that we don't know what your PreparedStatement looks like. And that we don't know anything about this table and what type of column you're trying to use. (Actually, not true: we know it's in an Oracle database.)

So absent that useful information I would suggest you try to insert it only in a column which is set up to receive timestamp information. And don't write SQL which tries to convert it to some other format; let the database driver take care of formatting.





What should I do in order to get the dateTime 2009-10-10 12:11:51.140 inserted into another table?

on the inserting table the datatype is DATE, inserting into a Oracle 10.0.2.0.1 database table.
on the retrieving table is a sqlserver and the datatype is datetime, the data is like 2009-10-10 12:11:51.140

I have changedto Stmt.setString(1, rs.getString("date")); However, I got an error as ORA-01861: literal does not match format string

Thanks

 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Kee Kee,

we were trying to get you on trach here:
https://coderanch.com/t/490526/JDBC/java/setNull-java-sql-Types-DATE#2206497

Have you tried the suggestions of that thread?
 
reply
    Bookmark Topic Watch Topic
  • New Topic