JDBC-JTDS 错误?对于日期和时间 (x) 类型的列
当我尝试从 ResultSetMetaData 获取列类型时 对于类型 date
和 time(x)
的方法 getColumnTypeName
,我得到 nvarchar
。对于其他类型似乎效果很好。这是一个错误吗?使用 ResultSet
getString("TYPE_NAME")
似乎没问题。 上运行
我正在执行查询时得到的 MSSQL2008
@a_horse_with_no_name
ResultSetMetaData
。在这种情况下,我没有任何桌子。这是代码片段
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;
}
When I'm trying to get column type from ResultSetMetaData
with method getColumnTypeName
for types date
and time(x)
, I'm gettingnvarchar
. 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个已知的 JTDS 错误,请参阅 sourceforge.net/p/jtds/bugs/679
This is a known JTDS bug, see sourceforge.net/p/jtds/bugs/679