Menu

#541 Timestamp is not a timestamp

v1.2
closed
momo
5
2012-09-28
2007-10-19
zvempa
No

I believe I've found a bug in version 1.2.2 of the jTDS driver, concering either the 'ts' JDBC escape or the method ResultSet.getTimeStamp().

If you run a query like SELECT {ts '2007-10-19 10:20:30.000'}, then ResultSet.getTimestamp() fails to recognize the result as a Timestamp.
The same bug applies for escapes 'd' and 't' in combination with methods getDate() and getTime().

I've been using Java version 1.5.0_11, on Windows XP (version 5.1, SP 2).

The following code snippet demonstrates the problem

public static void main (String[] args) {
try {
Connection conn = ... // open a SQL Server connection
Statement stmt = conn.createStatement ();
String sql = "SELECT {ts '2007-10-19 10:20:30.000'}";
ResultSet rset = stmt.executeQuery (sql);
if (rset.next ()) {
Timestamp ts = rset.getTimestamp (1);
System.out.println ("SUCCESS!");
}else {
System.out.println ("UNEXPECTED : No result!");
}

}catch (Exception e) {
  e.printStackTrace (System.out);
}

}//end main

Discussion

  • momo

    momo - 2009-09-02

    Thanks for reporting that issue! I can confirm this bug still exists in the current code base. It could be easily worked around in the jTDS code by appropriately parsing the varchar-type value returned by the DB but I feel this wouldn't be a reasonable solution since that still leaves the problem of incorrect meta date (e.g. type info) and involves some type conversion overhead.

     
  • Christopher Deckers

    We got affected by this bug at work: we changed our date generation logic to use the JDBC date escape syntax and had this unexpected side effect.
    We applied a work around where the issue showed up but considering the size of our code base there may be other places that should be patched...

    Is there any possibility to get this fixed?

    Cheers,
    -Christopher

     
  • Lukas Eder

    Lukas Eder - 2012-02-26

    I can confirm this issue for SQL Server, but it works for Sybase SQL Anywhere.
    I don't have any issues with sqljdbc4.jar, SQL Server's official JDBC driver.

    I'd like to vote for this to be fixed, too.

     
  • momo

    momo - 2012-09-28

    I fixed the error in SVN revision [1153].

    Cheers,
    momo

     
  • momo

    momo - 2012-09-28
    • status: open --> closed
    • assigned_to: momo
    • milestone: --> v1.2
     

Log in to post a comment.