> My Database support timestamp what i can not do is
> converting this number to a timestamp object.
The java.sql.Timestamp class has a constructor that takes a milliseconds time value as parameter (e.g. a value returned by the java.util.Date.getTime() method)
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html
Thank you all for your reply.
problem is that i recieve this number as string and when i try to
create a timestamp object from it by using the following code it face problem because Long class can not handle this number
java.sql.Timestamp ts = new Timestamp(Long.getLong("1183450890250"));
System.out.println(ts.getTime());
the above code return a NPE.
When i tried to insert that number as value of timestamp field database returned another harsh error like
Cannot insert a non-null value into a timestamp column.
What should do is
recieve an string which contains a number which is equal to Date.getTime()
insert it into timestamp column of a table in sqlserver
import java.sql.*;
public class Test122{
public static void main(String[] args) {
java.sql.Timestamp ts = new Timestamp(Long.parseLong("1183450890250"));
System.out.println(ts);
}
}
>javac Test122.java
>java Test122
2007-07-03 04:21:30.25
I have tried to do the following
java.sql.Timestamp ts = new Timestamp(Long.parseLong("1183450890250"));
and then i used
pstmt.setTimeStamp(ts);
But SQL server returned an error which indecatet that it can not store datetime into timestamp field.
It works when i change the field type to datetime but i need to use timestamp.
Any suggestion?
thanks
> You don't convert it, you let the database and the
> jdbc driver work that out for you... just insert it
> into a timestamp column, and join the army of
> programmers against daylight savings. They're armed
> with pencils, and have spent the last three years
> upgrading there them song... Sigh!
Only those not smart enough to run their database servers on UTC :)
> But SQL server returned an error which indecatet that it can not store
> datetime into timestamp field.
>
> It works when i change the field type to datetime but i need to use
> timestamp.
>
> Any suggestion?
A quick Google search on "SQL Server timestamp datetime" led me to the following quote from SQL Server Books Online : The SQL Server TIMESTAMP data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database.
Therefore, I guess that the data type that corresponds to a java.sql.Timestamp is probably DATETIME in SQL server.