Bug #60582 bug in com.mysql.jdbc.ResultSetRow.getTimestampFast and TIME
Submitted: 22 Mar 2011 10:37 Modified: 12 Apr 2013 18:20
Reporter: Sergei Golubchik Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.11 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[22 Mar 2011 10:37] Sergei Golubchik
Description:
Another bug in  com.mysql.jdbc.ResultSetRow.getTimestampFast, this time it concerns TIME type, not TIMESTAMP. The file has:

947 	// convert a String to a Time
948 	if ((length != 5) && (length != 8)) {
949 	  throw SQLError.createSQLException(Messages
950 	    .getString("ResultSet.Bad_format_for_Time____267") //$NON-NLS-1$
951 	    + new String(timeAsBytes)
952 	    + Messages.getString("ResultSet.___in_column__268")
953 	    + (columnIndex + 1),
954 	    SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
955 	}

while in fact a valid TIME value can have different lengths too.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

class b1 {
   public static void main(String[] args) {
        Connection conn;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            String url = "jdbc:mysql://127.0.0.1:3306/test";
            String userName = "test";
            String userPassword = "";
            conn = DriverManager.getConnection(url, userName, userPassword);
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SELECT time('810:34:10.112345')");
            ResultSet rs = stmt.getResultSet();
            rs.next();
            rs.getTime(1);
            rs.close();
        } catch (Exception e) {
            System.out.println("Exception: "+e);
            e.printStackTrace();
        }
    }
}

Suggested fix:
replace the if() with

if ((length != 5) && (length != 6) && ((length < 8) || length > 16) {
...

and handle microseconds below too.

Also, perhaps, you may remove (length != 5) && (length != 6)
as, I think, no valid time value can have HH:MM or HHH:MM format, MySQL always add seconds to it.
[24 Mar 2011 13:55] Mark Matthews
Other work for supporting fractional seconds will not start until WL#946 has passed architectural review and the fractional second units are specified.
[13 Sep 2012 21:07] Mark Matthews
This was fixed with http://bazaar.launchpad.net/~mysql/connectorj/5.1/revision/1107 in 2011, it supports MySQL-5.6.4 or later.
[12 Apr 2013 18:20] Paul DuBois
Noted in 5.1.19 changelog.

com.mysql.jdbc.ResultSetRow.getTimestampFast() did not account for
all valid TIME lengths.