1、加载数据库驱动
Class.forName("com.mysql.jdbc.Driver");
2、建立数据库连接池
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test2?user=root&password=1234");
3、由当前数据库连接生成一个数据操作对象
stmt=conn.createStatement();
4、获取PreparedStatement
PreparedStatement ps=conn.prepareStatement(sql);
5、写入要执行的sql语句
String sql = "insert into user(name,age,submitDate) value(?,?,now())";
6、用这个数据操作对象进行数据库操作
ps.executeUpdate();//更新
ps.executeUpdate();//查询
7、关闭数据库对象
ps.close();
8、关闭数据连接
conn.close() ;