Description:
MySQL Version: 5.0.0-alpha-nt.
Driver: mysql-connector-java-3.1-nightly-20040426 ( $Date: 2004/02/21 17:43:42 $, $Revision: 1.27.4.31 $ )
The column types obtained from a ResultSetMetaData that you can get by doing a SELECT don't always agree with the column type obtained from a ResultSetMetaData that you get from DatabaseMetaData.getColumns. For example, for a float column, one returns java.sql.Types.REAL and the other returns java.sql.Types.FLOAT. For a blob, one returns Types.LONGVARBINARY and the other returns a Types.VARBINARY.
How to repeat:
Use the following DDL to create the test table:
drop table if exists test1;
create table test1 (x float, y blob);
insert into test1 (x) values(1);
insert into test1 (x) values(2);
Run the following Java code:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("your connection info");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from test1 where 1 = 0;");
ResultSetMetaData rsmd = rs.getMetaData();
for(int i=1; i<=rsmd.getColumnCount(); i++){
System.out.println("ResultSetMetaData getColumnName: " + rsmd.getColumnName(i));
int type = rsmd.getColumnType(i);
System.out.println("ResultSetMetaData getColumnType: " + type);
}
stmt.close();
DatabaseMetaData dbmd = conn.getMetaData();
rs = dbmd.getColumns(null, null, "test1", "%");
while (rs.next()) {
String colName = rs.getString(4);
System.out.println("getColumns: column name: " + colName);
int type = rs.getInt(5);
System.out.println("getColumns: column type: " + type);
}
Observed Result:
ResultSetMetaData getColumnName: x
ResultSetMetaData getColumnType: 7
ResultSetMetaData getColumnName: y
ResultSetMetaData getColumnType: -4
getColumns: column name: x
getColumns: column type: 6
getColumns: column name: y
getColumns: column type: -3