PreparedStatement 和 Statement的区别:

  1. PreparedStatement 支持预编译,对于批量处理可以大大提高效率;Statement

不支持预编译

  1. PreparedStatement可以写参数化查询,比Statement能获得更好的性能。
  2. Prepared Statement可以操作Bobl类型的数据,
  3. Prepared Statement可以实现更高效率的批量操作。
  4. 可以解决Statement的拼串,sql注入问题。

JDBC 连接数据库的步骤

  1. 加载JDBC驱动程序
    1. 读取配置文件中的4个信息(root,password,url,driveClass)

2、获得 Connection con;DriverManager.getConnection(url , uname , password )。
3、创建 statement stmt;con.prepareStatement(sql)。
4、执行 Sql;stmt.executeQuery(sql)。
5、处理 ResultSet 结果集。
6、关闭 JDBC 对象。