总结基于Statement的JDBC编程
类或接口 | 描述 |
DriverManager类 | 驱动管理类 |
Connection接口 | 连接对象 |
Statement接口 | 发送sql到数据库并执行 |
ResultSet接口 | 结果集 |
方法 | 类或接口 | 描述 |
getConnection(url,username,password) | DriverManager类 | jdbc:mysql://ip:3306/数据库名?serverTimezone=值&characterEncoding=utf8 |
createStatement() | Connection接 口 | 创建statement对象 |
excute() | Statement接口 | 返回boolean |
excuteUpdate() | Statement接口 | 返回int |
excuteQuery() | Statement接口 | 返回ResultSet |
next() | ResultSet接口 | 返回boolean |
getString()、getInt().. | ResultSet接口 | 返回resultSet对应的值 |
PreparedStatement & Statement
1.PreparedStatement是Statement的子接口
2.PreparedStatement防止sql注入
3.PreparedStatement有预编译的功能,每次执行只是去改变参数,提高查询效率