Description:
I wrote a query with a large case statement that was several hundred characters long and
didn't have an "as fieldname" to use a column alias. The code that builds the SQL and
calls ResultSet.getDouble(fieldName) started throwing an exception that said the column
wasn't found. I wrote some test code that calls ResultSetMetaData.getColumnName() and the
name of the field had two garbage characters in front of the case statement and the field
name was truncated. The problem only happens when the field name is over 250 characters.
I am using the Connector/J 3.1.12 jar and 4.1.15 server on Windows XP. I cannot tell if
this is a client or server bug.
How to repeat:
Here is test code to reproduce the problem.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class BugTest {
public static void main(String args[]) {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/dbname", "username",
"password");
stmt = con.createStatement();
String colName =
"a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234567891";
rs = stmt.executeQuery("select curtime() as " + colName);
ResultSetMetaData meta = rs.getMetaData();
System.out.println("Original column name: " + colName);
System.out.println("Original column name length: " + colName.length());
System.out.println("Meta data column name: " + meta.getColumnName(1));
System.out.println("Meta data column length: " + meta.getColumnName(1).length());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Description: I wrote a query with a large case statement that was several hundred characters long and didn't have an "as fieldname" to use a column alias. The code that builds the SQL and calls ResultSet.getDouble(fieldName) started throwing an exception that said the column wasn't found. I wrote some test code that calls ResultSetMetaData.getColumnName() and the name of the field had two garbage characters in front of the case statement and the field name was truncated. The problem only happens when the field name is over 250 characters. I am using the Connector/J 3.1.12 jar and 4.1.15 server on Windows XP. I cannot tell if this is a client or server bug. How to repeat: Here is test code to reproduce the problem. import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class BugTest { public static void main(String args[]) { Connection con = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/dbname", "username", "password"); stmt = con.createStatement(); String colName = "a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a1234567891"; rs = stmt.executeQuery("select curtime() as " + colName); ResultSetMetaData meta = rs.getMetaData(); System.out.println("Original column name: " + colName); System.out.println("Original column name length: " + colName.length()); System.out.println("Meta data column name: " + meta.getColumnName(1)); System.out.println("Meta data column length: " + meta.getColumnName(1).length()); } catch (Exception e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } } }