try{Stringurl="jdbc:mysql://localhost:3306/book?";Class.forName("com.mysql.jdbc.Driver");//注册conn=DriverManager.getConnection(url,"root","123456");//连接statement=conn....
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);
}
展开