Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/ceshi";
String user = "root";
String password = "root";
Connection conn = DriverManager.getConnection(url,user,password);
String sql = "select * from book where bookID=?";
PreparedStatement ps = conn.prepareStatement(sql);
int bookID = 1;
ps.setInt(1,bookID);
rs = ps.executeQuery();
while(rs.next()){
System.out.println(rs.getString("stock"));
}
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/ceshi";
String user = "root";
String password = "root";
Connection conn = DriverManager.getConnection(url,user,password);
String sql = "update book set bookname=? where bookID=?";
int bookID = 1;
String name = "王武";
ps = conn.prepareStatement(sql);
ps.setString(1,name);
ps.setInt(2,bookID);
ps.executeUpdate();