Monday, December 3, 2001 01:43 PM
Based on your description of the problem I would venture a guess that the Date-Time value is being truncated on insert when passed using the Object type Timestamp. There may be some magic you can gleam from the following set of links which all seem to be leading to the 8 byte internal format that dates are stored in SQLServer.
I test an ACCESS datetime field with set/getTimstamp( Timestamp ) and found that the milliseconds element was truncated to 0 but the seconds element was preserved and valid.
My code snipplet looks like:
SQLServer DateTime Datatype Information Links
PreparedStatement pstmt1 = conctn.prepareStatement(
"insert into table2 ( col1, col2, date1 ) values ( ? , ?,? )" );
pstmt1.setString( 1, "testdate1" );
pstmt1.setInt( 2, 246 );
pstmt1.setTimestamp( 3, new Timestamp( System.currentTimeMillis() ), java.util.Calendar.getInstance() );
if( pstmt1.executeUpdate() > 0 )
System.out.println( "Did it!");
System.out.println( "Failed it!");
How DateTime is Stored
A Semi-Related Article
Find sp_fixedstring_to_datetime.sql on this page