在上一篇文章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);        }    }}

返回正确后果