java 如何把从数据库取得的值赋给一个二维数组?
try{Class.forName("com.mysql.jdbc.Driver").newInstance();//数据库驱动Stringurl="jdbc:mysql...
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"},
}; 展开
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个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询