我有一个如下表:
column1 - 12312,12235,43242,53465,82745 column2 - 12,45,56,N/A,N/A
我的java程序如下:
public Map<Integer, String> fetchResultValue(String query)
throws SQLException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException,
ClassNotFoundException, InstantiationException {
Map<Integer, String> m = new HashMap<Integer, String>();
PreparedStatement pstmt = null;
Connection con = null;
try {
con = getConnection(true);
pstmt = con.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
m.put(rs.getInt(1), rs.getString(2));
}
return m;
} finally {
this.cleanResources(con, pstmt);
}
}
我得到了读取 column2 值的异常,我最初尝试使用 rs.getInte(2) 而不是 rs.getString(2) 但即使那样我也得到了那个异常,所以我该如何读取该列值。