public class Demo01 {
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
//1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//2.打开连接
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pxhome", "root", "root");
//3.sql语句
String sql = "insert into dept values(?,?,?)";
//4.创建预执行sql语句方法
PreparedStatement pstat = conn.prepareStatement(sql);
//5.给sql语句的占位符添加具体指
pstat.setObject(1, null);
pstat.setObject(2, "游击部");
pstat.setObject(3, "兰州");
//6.执行方法并记录影响行数
int rows = pstat.executeUpdate();
System.out.println(rows+"条记录被执行......");
//7.关闭资源
conn.close();
}
}