摘要:list
List<Map<String,String>> listData = new ArrayList<Map<String, String>>();
Map<String,String> mapData = new HashMap<String,String>();
DBOperate dbo = new DBOperate();
//select * from sakila.actor;
List<Map> listActor2 = dbo.select("getAllActor", null);
//SELECT * FROM sakila.dynamiccolumn;
List<Map> listActor3 = dbo.select("getDynamiccolumn", null);
for (int j=0;j<listActor3.size();j++) {
Map rowMap2 = listActor3.get(j);
System.out.print("; Column Name = " + rowMap2.get("nm"));
}
System.out.println("");
for (int i=0;i<listActor2.size();i++) {
Map rowMap = listActor2.get(i);
for (int j=0;j<listActor3.size();j++) {
Map rowMap2 = listActor3.get(j);
//System.out.print("; value = " + rowMap.get(rowMap2.get("nm")));
mapData.put(rowMap2.get("nm").toString(), rowMap.get(rowMap2.get("nm")).toString());
listData.add(mapData);
}
//System.out.println("");
//System.out.println("f_nm2:==========" + rowMap.get("first_name"));
}
for (Map<String,String> s : listData) {
System.out.println(s);
}
=================================
List<Map<String,String>> listData = new ArrayList<Map<String, String>>();
Map<String,String> mapData = new HashMap<String,String>();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=Big5",
"root","admin");
System.out.println("Connected to the database");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select * from sakila.actor";
ResultSet rs = stmt.executeQuery(sql);
Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql2 = "SELECT * FROM sakila.dynamiccolumn";
ResultSet rs2 = stmt2.executeQuery(sql2);
while(rs.next()) {
while(rs2.next()) {
System.out.print(rs2.getString("nm") +" ===== "+ rs.getString(rs2.getString("nm")));
mapData.put(rs2.getString("nm"), "''"+rs.getString(rs2.getString("nm")) +" ''''");
}
listData.add(mapData);
System.out.println("");
}
request.setAttribute("userinfoList", listData);
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}