public class ApacheDBUtils { @Test public void testQueryMany() throws SQLException { // 得到连接 druid Connection connect = DruidUtil.connect(); QueryRunner queryRunner = new QueryRunner(); String sql = "select * from actor where id >= ?"; /** * query 方法:执行sql语句 ---> 得到resultSet ---> 封装到 arrayList中 * new BeanListHandler<>(Actor.class) -- 在将 resultSet封装到arrayList中 * 底层使用反射机制,去获取Actor的属性,完成封装 * 1 就是给 sql语句中的? 赋值,可以写多个 * resultSet, preparedStatement在底层中产生并关闭 */ /** * query 方法源码: * if (conn == null) { // 先进行判断,如果没有连接,就抛出异常 * throw new SQLException("Null connection"); * } else if (sql == null) { // 如果没有sql语句,但有连接,就关闭连接后抛出异常“Null SQL statement” *
Apache dbUtils工具类的初使用和query方法的源码浅析
最新推荐文章于 2023-06-19 21:53:01 发布