import java.sql.*;
import java.util.ResourceBundle;
public class PrepareStatement_Test02 {
public static void main(String[] args) {
Connection c =null;
PreparedStatement ps =null;
ResultSet rs = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver"); //注册驱动
String url = "jdbc:mysql://localhost:3306/jdbctest";
String user = "root";
String password ="root";
c = DriverManager.getConnection(url,user,password); // 连接数据库
if(c!=null){ //判断是否连接成功
System.out.println("连接成功");
}
//实现插入数据
/* String k1 = "insert into book values(?,?,?,?,?)";
ps = c.prepareStatement(k1);
ps.setInt(1,1);
ps.setString(2,"JavaEE教学");
ps.setString(3,"约瑟夫");
ps.setString(4,"光明出版社");
ps.setString(5,"2001-10-5");*/
//实现删除数据的功能
/* String k2 = "delete from book where bSno=? ";
ps = c.prepareStatement(k2);
ps.setInt(1,1);
*/
//实现修改操作
/* String k3 = "update book set bname =?,bAutor=?,bPress=?,bYear=? where bSno = ?";
ps = c.prepareStatement(k3);
ps.setString(1,"Python编程");
ps.setString(2,"老师");
ps.setString(3,"北京出版社");
ps.setString(4,"2021-10-23");
ps.setInt(5,1);*/
//int i =ps.executeUpdate();
//实现查询功能
String k4 = "select * from book where bSno=?";
ps = c.prepareStatement(k4);
ps.setInt(1,1);
rs = ps.executeQuery();
while(rs.next()){
String bSno = rs.getString("bSno");
String bname = rs.getString("bname");
String bAutor = rs.getString("bAutor");
String bPress = rs.getString("bPress");
String bYear = rs.getString("bYear");
System.out.println("bSno:"+bSno+" bname:"+bname+"--bAutor:"