dbTalk Databases Forums  

Problem retrieving a time stamp using JConnect 7 and SQL Anywhere 11

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Problem retrieving a time stamp using JConnect 7 and SQL Anywhere 11 in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Julian Molina
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.