java 如何把从数据库取得的值赋给一个二维数组?

try {

Class.forName("com.mysql.jdbc.Driver").newInstance();// 数据库驱动

String url = "jdbc:mysql://localhost:3306/project1";// 数据库链接地址

String user = "root";// 用户名

String password = "123456";// 密码

Connection conn = DriverManager.getConnection(url, user, password);// 建立connection

Statement stmt = conn.createStatement();

conn.setAutoCommit(false);// 更改jdbc事务的默认提交方式

String sql = "select * from 3ad where id=11310169;";// 查询语句

ResultSet rs = stmt.executeQuery(sql);// 得到结果集

conn.commit();// 事务提交

conn.setAutoCommit(true);// 更改jdbc事务的默认提交方式

while (rs.next()) {// 如果有数据,取第一列添加如list

list.add(rs.getString("name"));

tt = rs.getString("name");

list.add(rs.getString("id"));

list.add(rs.getString("3adno"));

list.add(rs.getString("Email"));

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

String tax[][] ={ {"1","2","3","4"},

{"1","2","3","4"},

{"1","2","3","4"},

{"1","2","3","4"},

{"1","2","3","4"},

};

第1个回答  2014-06-07
for(int i = 0;i < list.size(); i++){
for(int j = 0; j < tax.length; j++){
for(int m = 0;m < 4;m++){
tax[j][m] = list.get(i);
}

}

}本回答被提问者采纳
相似回答