Following test case does not work with jconn2.jar.
void testSybaseTimeStamp(Connection con) throws SQLException {
try {
//Create the Table
Statement s = conn.createStatement();
String sqlStatement;
try {
sqlStatement = "DROP TABLE DATATYPES";
System.out.println(sqlStatement);
s.executeUpdate(sqlStatement);
} catch (SQLException e) {
System.out.println("Table does not exist...");
}
//Sybase
sqlStatement = "CREATE TABLE DATATYPES(PK INT NOT NULL, TIMESTAMPDATA DATETIME) ";
System.out.println(sqlStatement);
s.executeUpdate(sqlStatement);
//Initialize arbitrary timestamp value
java.sql.Timestamp insertedTs = new java.sql.Timestamp(900000L);
//insertedTs.setNanos(123456789);
insertedTs.setNanos(123000000);
System.out.println("\nTimestamp to insert = " + insertedTs);
System.out.println("Timestamp to insert nanons = " + insertedTs.getNanos());
sqlStatement = "INSERT INTO DATATYPES (PK, TIMESTAMPDATA) VALUES(1,?)";
System.out.println(sqlStatement);
PreparedStatement ps = conn.prepareStatement(sqlStatement);
ps.setTimestamp(1, insertedTs); //TIMESTAMPDATA
ps.executeUpdate();
sqlStatement = "\nSELECT TIMESTAMPDATA FROM DATATYPES where pk = 1";
System.out.println(sqlStatement);
ps = conn.prepareStatement(sqlStatement);
ResultSet rs = ps.executeQuery();
rs.next();
Timestamp retrievedTs = rs.getTimestamp(1);
System.out.println("Retrieved Timestamp = " + retrievedTs);
System.out.println("Retrieved Timestamp nanons = " + retrievedTs.getNanos());
if(!insertedTs.equals(retrievedTs) ) {
System.out.println("Inserted and Retrieved Timestamp do not match!!");
}
} catch (SQLException e) {
SQLException currentException = e;
do {
System.out.println("Exception is" + currentException);
System.out.println("getErrorCode()" + currentException.getErrorCode());
System.out.println("getSQLState()" + currentException.getSQLState());
currentException = currentException.getNextException();
} while (currentException != null);
}
}
Following is output from above method
DROP TABLE DATATYPES
CREATE TABLE DATATYPES(PK INT NOT NULL, TIMESTAMPDATA DATETIME)
Timestamp to insert = 1969-12-31 16:15:00.123
Timestamp to insert nanons = 123000000
INSERT INTO DATATYPES (PK, TIMESTAMPDATA) VALUES(1,?)
SELECT TIMESTAMPDATA FROM DATATYPES where pk = 1
Retrieved Timestamp = 1969-12-31 16:15:00.123
Retrieved Timestamp nanons = 123333333
Inserted and Retrieved Timestamp do not match!!
###@###.### 2004-02-18
Following are details on the driver
getDriverMajorVersion():5
getDriverMinorVersion():5
getDriverName():jConnect (TM) for JDBC (TM)
getDriverVersion():jConnect (TM) for JDBC(TM)/5.5(Build 25137)/P/EBF10000/JDK12/Sun Jan 6 21:57:04 2002
###@###.### 2004-02-18
void testSybaseTimeStamp(Connection con) throws SQLException {
try {
//Create the Table
Statement s = conn.createStatement();
String sqlStatement;
try {
sqlStatement = "DROP TABLE DATATYPES";
System.out.println(sqlStatement);
s.executeUpdate(sqlStatement);
} catch (SQLException e) {
System.out.println("Table does not exist...");
}
//Sybase
sqlStatement = "CREATE TABLE DATATYPES(PK INT NOT NULL, TIMESTAMPDATA DATETIME) ";
System.out.println(sqlStatement);
s.executeUpdate(sqlStatement);
//Initialize arbitrary timestamp value
java.sql.Timestamp insertedTs = new java.sql.Timestamp(900000L);
//insertedTs.setNanos(123456789);
insertedTs.setNanos(123000000);
System.out.println("\nTimestamp to insert = " + insertedTs);
System.out.println("Timestamp to insert nanons = " + insertedTs.getNanos());
sqlStatement = "INSERT INTO DATATYPES (PK, TIMESTAMPDATA) VALUES(1,?)";
System.out.println(sqlStatement);
PreparedStatement ps = conn.prepareStatement(sqlStatement);
ps.setTimestamp(1, insertedTs); //TIMESTAMPDATA
ps.executeUpdate();
sqlStatement = "\nSELECT TIMESTAMPDATA FROM DATATYPES where pk = 1";
System.out.println(sqlStatement);
ps = conn.prepareStatement(sqlStatement);
ResultSet rs = ps.executeQuery();
rs.next();
Timestamp retrievedTs = rs.getTimestamp(1);
System.out.println("Retrieved Timestamp = " + retrievedTs);
System.out.println("Retrieved Timestamp nanons = " + retrievedTs.getNanos());
if(!insertedTs.equals(retrievedTs) ) {
System.out.println("Inserted and Retrieved Timestamp do not match!!");
}
} catch (SQLException e) {
SQLException currentException = e;
do {
System.out.println("Exception is" + currentException);
System.out.println("getErrorCode()" + currentException.getErrorCode());
System.out.println("getSQLState()" + currentException.getSQLState());
currentException = currentException.getNextException();
} while (currentException != null);
}
}
Following is output from above method
DROP TABLE DATATYPES
CREATE TABLE DATATYPES(PK INT NOT NULL, TIMESTAMPDATA DATETIME)
Timestamp to insert = 1969-12-31 16:15:00.123
Timestamp to insert nanons = 123000000
INSERT INTO DATATYPES (PK, TIMESTAMPDATA) VALUES(1,?)
SELECT TIMESTAMPDATA FROM DATATYPES where pk = 1
Retrieved Timestamp = 1969-12-31 16:15:00.123
Retrieved Timestamp nanons = 123333333
Inserted and Retrieved Timestamp do not match!!
###@###.### 2004-02-18
Following are details on the driver
getDriverMajorVersion():5
getDriverMinorVersion():5
getDriverName():jConnect (TM) for JDBC (TM)
getDriverVersion():jConnect (TM) for JDBC(TM)/5.5(Build 25137)/P/EBF10000/JDK12/Sun Jan 6 21:57:04 2002
###@###.### 2004-02-18