Problem with JDBC resultset type mapping
"Miłosz Hulbój" <[email protected]>
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <[email protected]> |
Hello, I am observing a strange behaviour of JDBC resultset type assignment. The behaviour seems to be induced by using GROUP BY and CONCAT. Here are the details about the setup: mysql-connector-java-3.1.13 mysql-connector-java-5.0.3 MySQL 4.1.14 under Linux Code and table info has been attached to this message. Can anyone confirm this behaviour? I have looked at the bugs and couldn't find anything related there. Regards, Milosz -- Milosz Hulboj https://www.linkedin.com/profile?viewProfile=&key=1467390 -- MySQL Java Mailing List For list archives: http://lists.mysql.com/java To unsubscribe: http://lists.mysql.com/[email protected]
example.java
(text/x-java, 1.8 KB)
import java.sql.*;
/*
mysql> desc iris;
+-------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+-------+
| sepallength | double | YES | | NULL | |
| sepalwidth | double | YES | | NULL | |
| petallength | double | YES | | NULL | |
| petalwidth | double | YES | | NULL | |
| Class | mediumtext | YES | | NULL | |
+-------------+------------+------+-----+---------+-------+
*/
class example
{
public static void main (String[]args) {
try {
Class.forName ("org.gjt.mm.mysql.Driver");
} catch (Exception e) {
System.out.println ("AAAA");
}
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
ResultSetMetaData md = null;
try {
connection = DriverManager.getConnection ("jdbc:mysql:///aqq", "", "");
statement = connection.createStatement ();
rs = statement.executeQuery("SELECT concat(Class,petallength), COUNT(*) FROM `iris` GROUP BY `concat(Class,petallength)`");
md = rs.getMetaData ();
for (int i = 1; i <= md.getColumnCount (); i++) {
System.out.println ("Column: " + md.getColumnName (i) + " SQLType: " + md.getColumnType (i)); // -4 is LONGVARBINARY!!!
}
rs = statement.executeQuery ("SELECT concat(Class,petallength) FROM `iris`");
md = rs.getMetaData ();
for (int i = 1; i <= md.getColumnCount (); i++) {
System.out.println ("Column: " + md.getColumnName (i) + " SQLType: " + md.getColumnType (i)); // 12 is VARCHAR - OK
}
statement.close ();
connection.close ();
} catch (SQLException ex) {
System.out.println ("SQLException: " + ex.getMessage ());
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("VendorError: " + ex.getErrorCode ());
}
}
}