Vector vctRtn = null;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
boolean bResult = stmt.execute(strSQL);
vctRtn = new Vector();
if (bResult) {
rs = stmt.getResultSet();
ResultSetMetaData rsmd = rs.getMetaData();
Vector vctColName = new Vector();
for (int i = 0; i < rsmd.getColumnCount(); i++) {
String strColName = rsmd.getColumnName(i + 1);
vctColName.addElement(strColName.toUpperCase());
}
Map map;
for (; rs.next(); vctRtn.addElement(map)) {
map = new HashMap();
for (int i = 0; i < vctColName.size(); i++) {
Object value = rs.getObject(vctColName.get(i).toString());
if (value != null && value instanceof java.sql.Timestamp) {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
value = sdf.format((Timestamp)value);
}
map.put(vctColName.get(i) , value);
}
}
}
return vctRtn;
} catch (SQLException e) {
if (e.getErrorCode() == 0) {
return null;
} else {
logger.error(e.getMessage()+"SQL语句"+strSQL);
}
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return vctRtn;
}
这是读取数据,将数据弄成集合的一个方法。可是今天数据库下发的数据比较多,但也只有6万多条,直接内存就彪到了600多M,我把这些数据放到EXCLE里也只有20多M啊。求各位大神告诉我是怎么回事?这个该怎么优化?