急求mysql数据库中表的内容怎么在netbeans中table表格中显示? 25
这是代码try{Stringurl="jdbc:mysql://localhost:3306/book?";Class.forName("com.mysql.jdbc.D...
这是代码
try {
String url = "jdbc:mysql://localhost:3306/book?";
Class.forName("com.mysql.jdbc.Driver"); //注册
conn = DriverManager.getConnection(url, "root", "123456"); //连接
statement = conn.createStatement();
sql = "select * from book2 where book_id=" + colValue + "";
rs = statement.executeQuery(sql);
int i = 0;
int j = 0;
while (rs.next()) {
jTable1.setValueAt(rs.getString(1), i, j);
jTable1.setValueAt(rs.getString(2), i, j + 1);
jTable1.setValueAt(rs.getString(3), i, j + 2);
jTable1.setValueAt(rs.getString(4), i, j + 3);
jTable1.setValueAt(rs.getString(5), i, j + 4);
jTable1.setValueAt(rs.getString(6), i, j + 5);
jTable1.setValueAt(rs.getString(7), i, j + 6);
jTable1.setValueAt(rs.getString(8), i, j + 7);
i++;
j = 0;
}
} catch (Exception e) {
System.out.println(e);
} 展开
try {
String url = "jdbc:mysql://localhost:3306/book?";
Class.forName("com.mysql.jdbc.Driver"); //注册
conn = DriverManager.getConnection(url, "root", "123456"); //连接
statement = conn.createStatement();
sql = "select * from book2 where book_id=" + colValue + "";
rs = statement.executeQuery(sql);
int i = 0;
int j = 0;
while (rs.next()) {
jTable1.setValueAt(rs.getString(1), i, j);
jTable1.setValueAt(rs.getString(2), i, j + 1);
jTable1.setValueAt(rs.getString(3), i, j + 2);
jTable1.setValueAt(rs.getString(4), i, j + 3);
jTable1.setValueAt(rs.getString(5), i, j + 4);
jTable1.setValueAt(rs.getString(6), i, j + 5);
jTable1.setValueAt(rs.getString(7), i, j + 6);
jTable1.setValueAt(rs.getString(8), i, j + 7);
i++;
j = 0;
}
} catch (Exception e) {
System.out.println(e);
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏25(财富值+成长值)
1个回答
2015-06-25
展开全部
获取数据库内容:
public static String getUserName(String ID){
String name = "";
try{
conn = new QQJDBCConnector().getConnection();
stmt=conn.createStatement();
sql="select user.name from user where user.ID = '"+ID+"'";
rs=stmt.executeQuery(sql);
while(rs.next()) {
name=rs.getString("name");
}
stmt.close() ;
conn.close() ;
}
catch (Exception e){
System.out.println(e.getMessage());
}
return name;
}
public static String getUserName(String ID){
String name = "";
try{
conn = new QQJDBCConnector().getConnection();
stmt=conn.createStatement();
sql="select user.name from user where user.ID = '"+ID+"'";
rs=stmt.executeQuery(sql);
while(rs.next()) {
name=rs.getString("name");
}
stmt.close() ;
conn.close() ;
}
catch (Exception e){
System.out.println(e.getMessage());
}
return name;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询