您的位置:首页 > 数据库 > Oracle

ibatis使用HashMap作为返回结果时DB2,ORACLE,MYSQL对KEY大小写不同

2014-12-25 19:28 555 查看
源代码如下:
private void initialize(ResultSet rs) {
if (getResultClass() == null)
throw new SqlMapException("The automatic ResultMap named " + getId() + " had a null result class (not allowed).");
if (Map.class.isAssignableFrom(getResultClass()))
initializeMapResults(rs);
else if (getDelegate().getTypeHandlerFactory().getTypeHandler(getResultClass()) != null)
initializePrimitiveResults(rs);
else if (DomTypeMarker.class.isAssignableFrom(getResultClass()))
initializeXmlResults(rs);
else
initializeBeanResults(rs);
}

private void initializeMapResults(ResultSet rs) {
try {
List resultMappingList = new ArrayList();
ResultSetMetaData rsmd = rs.getMetaData();
int i = 0; for (int n = rsmd.getColumnCount(); i < n; i++) {
String columnName = getColumnIdentifier(rsmd, i + 1);
columnName=columnName.toUpperCase();//将KEY转为大写,保持一致性
ResultMapping resultMapping = new ResultMapping();
resultMapping.setPropertyName(columnName);
resultMapping.setColumnName(columnName);
resultMapping.setColumnIndex(i + 1);
resultMapping.setTypeHandler(getDelegate().getTypeHandlerFactory().getTypeHandler(Object.class));
resultMappingList.add(resultMapping);
}

setResultMappingList(resultMappingList);
}
catch (SQLException e) {
throw new RuntimeException("Error automapping columns. Cause: " + e);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: