关于java:Druid测试Druid工具类

4次阅读

共计 737 个字符,预计需要花费 2 分钟才能阅读完成。

在上一篇文章 Druid- 创立 Druid 连接池中, 咱们曾经创立好了 Druid 连接池, 也就是创立好 Druid 工具类

接下来咱们就应用该工具类执行 SQL 语句, 测试该工具类是否能够失常工具

本文应用的数据是


/**
 *   我的项目形容: 应用自定义编写的数据库 Druid 连接池的工具类获取连贯进行 sql 查问操作
 *   作   者: chain.xx.wdm
 *   备   注:
 */

public class DruidPoolTest {public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        try {
            // 1. 获取连贯
            connection = DruidUtils.getConnection();
            // 2. 获取 Statement 对象,执行 sql 查问
            statement = connection.createStatement();
            resultSet = statement.executeQuery("select name from employee where salary between 3000 and 5000");
            // 3. 处理结果集
            while(resultSet.next()){String ename = resultSet.getString("name");
                System.out.println(ename);
            }
        } catch (SQLException throwables) {throwables.printStackTrace();
        } finally {
            // 4. 敞开对象
            DruidUtils.close(connection, statement, resultSet);
        }
    }
}

返回正确后果

正文完
 0