//连接DB
AXXX{
String sDBDriver = "oracle.jdbc.OracleDriver";
String url = "jdbc:oracle:thin:@43.82.101.107:1541:gaudi01";
String user = "scott";
String pwd = "tiger";
Class.forName(sDBDriver);
conn = DriverManager.getConnection(url, user, pwd);
String sql = "select * from bigtable order by object_id desc";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
List list = getList(rs);
}
//RS转换为List
public static List getList(ResultSet rs) throws Exception{
List list = new ArrayList();
ResultSetMetaData rd = rs.getMetaData();
while(rs.next()){
int icount = rd.getColumnCount();
Map map = new HashMap();
for(int i = 1 ;i<=icount;i++){
map.put(rd.getColumnName(i),rs.getObject(rd.getColumnName(i)));
}
list.add(map);
}
return list;
}
阅读(709) | 评论(0) | 转发(0) |