HikariCP连接Trafodion样例

HikariCP号称是性能最好的JDBC连接池,其在GitHub上地址:https://github.com/brettwooldridge/HikariCP
至少HirakiCP与其他连接池孰优孰劣,本文不作详细阐述,本文主要描述如何通过HirakiCP实现一个简单的与Trafodion数据库的连接。
本实验的开发环境是Windows 7 + Eclispe
所引入的第三方包如下,

这里写图片描述

Java样例代码如下,

package cn.com.esgyn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class HirakiCP {
    private static HikariConfig config;
    private static HikariDataSource pool;
    private static Connection conn;
    private static String sql = "select count(*) as cnt from trafodion.seabase.test_table";
    private static PreparedStatement ps;
    private static ResultSet rs;
    private static String DRIVER_NAME = "org.trafodion.jdbc.t4.T4Driver";
    private static String JDBC_URL = "jdbc:t4jdbc://192.168.0.16:23400/:";
    private static String USERNAME = "zz";
    private static String PASSWORD = "zz";

    public static void main(String[] args) throws SQLException {
        //create a connection pool. The pool usually is a global variable.
        config = new HikariConfig();
        config.setMaximumPoolSize(10);
        config.setIdleTimeout(60000);
        config.setDriverClassName(DRIVER_NAME);
        config.setJdbcUrl(JDBC_URL);
        config.setUsername(USERNAME);
        config.setPassword(PASSWORD);
        config.setConnectionTestQuery("values(1)");
        config.setJdbc4ConnectionTest(false);
        pool = new HikariDataSource(config);
        //get a connection from connection pool
        conn = pool.getConnection();
        //execute query
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString("cnt"));
        }
        //conn will return back to pool
        conn.close();

    }

}

你可能感兴趣的:(HikariCP连接Trafodion样例)