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);
}
}
相关文章推荐
- MSSQL,ORACLE,DB2,MYSQL,Access各类数据库使用GUID作为主键
- Oracle,Sql Server, MySql, DB2使用sql分页(ZZ)
- 使用mysql_fetch_row()以数组的形式返回查询结果
- Ibatis 中使用存储过程以及sys_refcursor 返回结果
- 使用ibatis将数据库从oracle迁移到mysql的几个修改点
- 与Oracle有所不同,ibatis中实现获取mysql自增序列值
- 使用ibatis将数据库从oracle迁移到mysql的几个修改点
- 使用mysql_fetch_row()以数组的形式返回查询结果
- ibatis返回HashMap结果类型与映射
- mysql查询中实现oracle中的rownum函数的效果,返回每行查询结果的行序号
- 【转】ibatis中mysql存储过程返回结果集
- ibatis返回结果映射到HashMap时,列名无效的问题
- MySql使用全记录3 -----以中文作为查询条件时结果为空的原因以及两个MySql小知识点(varchar、单双引号)
- iBatis自动生成的主键 返回主键 (Oracle,Sql Server,Mysql,SQLite)
- C#连接Access、SQL Server、Oracle、MySQL、DB2和SyBase六种不同数据库的程序源码
- 可遇不可求的Question之MySqlClient与ODBC访问字段返回不同结果篇
- 使用mysql_fetch_object()以对象的形式返回查询结果
- ibatIS中返回结果map 并使用list获取
- ibatis like mysql oracle sqlserver db2
- Oracle 中使用游标返回结果集