一次,用到了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中的值:
最后发现HashMap中存的值:KEY:BUSI_CODE VALUE:7450
费尽周折,发现原因尽然是Oracle会将所有表名和字段名变为大写......
使用背景:
/**
* 查询记录封装在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会将所有表名和字段名变为大写......