Problem retrieving a time stamp using JConnect 7 and SQL Anywhere 11 -
11-01-2010
, 04:54 PM
Hi,
I'm using Sql Anywhere 11.0.1.2475 on Linux 2.6.18-164.el.5 with
JConnect 7.0.26518. This is what's stored in the database:
Test_UID,TestDate
1,'2010-11-02 00:30:00.000'
2,'2010-11-02 00:45:00.000'
3,'2010-11-02 01:15:40.000'
4,'2010-11-01 23:16:14.000'
5,'2010-11-01 12:26:30.000'
6,'2010-11-02 00:59:59.000'
7,'2010-11-01 00:00:10.000'
If I use jConnect 7 to retrieve the datetime values from the database,
first as a timestamp and then as a string, I get this:
1, 2010-11-01 23:30:00.0 * 2010-11-02 00:0-30:00.000000
2, 2010-11-01 23:45:00.0 * 2010-11-02 00:0-15:00.000000
3, 2010-11-02 01:15:40.0 * 2010-11-02 01:15:40.000000
4, 2010-11-01 23:16:14.0 * 2010-11-01 23:16:14.000000
5, 2010-11-01 12:26:30.0 * 2010-11-01 12:26:30.000000
6, 2010-11-01 23:59:59.0 * 2010-11-02 00:0-1:59.000000
7, 2010-11-01 00:00:00.0 * 2010-11-01 00:00:00.000000
As you can see, (1) and (2) change their value when retrieved from the
database, the rest stay the same.
This is the code of the application:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
public class Test
{
/**
* @param args
*/
public static void main( String[] args )
{
try {
Class.forName("com.sybase.jdbc4.jdbc.SybDriver").n ewInstance();
String url = "jdbc:sybase:Tds:localhost?
ServiceName=bncdb";
Connection conn = DriverManager.getConnection(url,
"bncdba", "mybncsql");
PreparedStatement stmt = conn.prepareCall( "select
Test_Uid, TestDate from TB_Test" );
ResultSet result = stmt.executeQuery();
while (result.next()) {
int testUid = result.getInt( "Test_Uid" );
Timestamp ts = result.getTimestamp( "TestDate" );
String tsS =
result.getString( "TestDate" );
System.out.println(testUid + " " + ts + " * " + tsS);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Julian Molina |