问题描述
当我尝试从 ResultSetMetaData
获取列类型时使用方法 getColumnTypeName
获取类型 日期
和 时间(x)
,我收到了
nvarchar
。对于其他类型似乎它工作正常。这是一个错误吗?使用 ResultSet
getString(TYPE_NAME)
似乎没问题。我正在运行 MSSQL2008
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
@a_horse_with_no_name
ResultSetMetaData
执行查询时我得到了。在那种情况下,我没有任何表格。以下是代码段
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;
}
推荐答案
这是一个已知的JTDS错误,请参阅
This is a known JTDS bug, see sourceforge.net/p/jtds/bugs/679
这篇关于JDBC - JTDS错误?对于日期和时间类型的列(x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!