六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 56|回复: 0

HashMap--ResultSetMetaData--Oracle--乱记

[复制链接]

升级  48%

30

主题

30

主题

30

主题

秀才

Rank: 2

积分
122
 楼主| 发表于 2013-1-14 07:14:59 | 显示全部楼层 |阅读模式
一次,用到了LinkedList<HashMap<String, String>> retList=new LinkedList<HashMap<String,String>>();

使用背景:

/**
  * 查询记录封装在list中
  * @param conn
  * @param sql
  * @return
  * @throws SQLException
  */
public static LinkedList<HashMap<String, String>> getListRecords(Connection conn, String sql) throws SQLException;



HashMap中存放的是:

   ResultSetMetaData rsmd = rs.getMetaData() ;
   
   String[] columns = getColumnName(rsmd);

   while (rs.next())
   {
    recordMap = new HashMap<String, String>();
    for (int i = 0; i < columns.length; i++)
    {
     recordMap.put(columns[i], rs.getString(columns[i]));
    }
    retList.add(recordMap);
   }


在取出HashMap后,总是get不到HashMap值,字段名是数据库中搜出的列名busi_code......

HashMap.get("busi_code")=NULL





相关JDK: 方法无字段大小写的规定

java.sql
Interface ResultSetMetaData
getColumnName
String getColumnName(int column)
                     throws SQLExceptionGet the designated column's name.

Parameters:
column - the first column is 1, the second is 2, ...
Returns:
column name
Throws:
SQLException - if a database access error occurs


--------------------------------------------------------------------------------




SQL语句:

select busi_code from tb_experience_interface where busi_flag='1';





经过遍历HashMap中的值:

for(HashMap<String, String> record:retList){           for (Map.Entry entry : record.entrySet()) {                Object key = entry.getKey( );                Object value = entry.getValue();              System.out.print("KEY:" + key + "\t");                System.out.println("VALUE:" + value);            }                     // String busiCode=record.get("BUSI_CODE");}

最后发现HashMap中存的值:KEY:BUSI_CODE        VALUE:7450



费尽周折,发现原因尽然是Oracle会将所有表名和字段名变为大写......
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表