• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql getTimestamp

 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your column is dateTime and not timestamp, why bother with timestamp at all?
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Kee Kee,

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

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