JDBC - JTDS bug ? For columns of type date and time(x)

孤者浪人 提交于 2019-12-20 03:00:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!