日期:2014-05-16 浏览次数:20428 次
String sql = "select count(*) as num from yxtj_dqjl a"; System.out.println("result:"+jdbcTemplate.queryForList(sql));
result:[{=6}]
String sql = "select count(*) as testcount from test"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); System.out.println("columnName=" + rsmd.getColumnName(1)); System.out.println("columnLabel=" + rsmd.getColumnLabel(1));
getColumnName= getColumnLabel=testid
public Object mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map mapOfColValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { [color=red]String key = getColumnKey(rsmd.getColumnName(i));[/color] Object obj = getColumnValue(rs, i); mapOfColValues.put(key, obj); } return mapOfColValues; }
String key = getColumnKey(rsmd.getColumnLabel(i));
result:[{num=6}]