问题
When I'm trying to get column type from ResultSetMetaData
with method getColumnTypeName
for types date
and time(x)
, I'm getting
nvarchar
. For other types seems it works fine. Is this a bug? With ResultSet
getString("TYPE_NAME")
it seems ok. I'm running on MSSQL2008
@a_horse_with_no_name
ResultSetMetaData
I'm getting when executing query. In that case I haven't any tables. Here is the code snippet
if (resultType == ResultMappingType.QUERY){ // For Query
Statement statement = con.createStatement();
ResultSet rs = executeAndValidateQuery(statement, resultName);
ResultSetMetaData rsMeta = rs.getMetaData();
for( int i = 1 ; i < rsMeta.getColumnCount()+1 ; i ++ ){
columnInfo.put( rsMeta.getColumnName(i), rsMeta.getColumnTypeName(i));
}
}else { //For View & Table
ResultSet rsColumns = meta.getColumns(catalog, schemaPattern, resultName, null);
while (rsColumns.next()){
columnInfo.put(rsColumns.getString("COLUMN_NAME"), rsColumns.getString("TYPE_NAME"));
}
}
....
private ResultSet executeAndValidateQuery(Statement statement, String query) throws KbValidationException{
ResultSet rs = null;
try{
rs = statement.executeQuery(query);
}
catch(SQLException ex){
throw new KbValidationException(ex.getMessage());
}
return rs;
}
回答1:
This is a known JTDS bug, see sourceforge.net/p/jtds/bugs/679
来源:https://stackoverflow.com/questions/7885459/jdbc-jtds-bug-for-columns-of-type-date-and-timex