4

我有以下代码来连接到 oracle 数据库。但是使用 hikaricp 我得到了例外。

java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL

代码:

private static HikariDataSource dataSource() {
    final HikariDataSource hikariDataSource = new HikariDataSource();
    hikariDataSource.setMaximumPoolSize(100);
    hikariDataSource.setMinimumIdle(10);
    hikariDataSource.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");

    Properties properties = new Properties();
    properties.put("user", "user");
    properties.put("password", "pass");
    properties.put("databaseName", "XE");
    properties.put("serverName", "192.168.21.13");
    properties.put("portNumber", "1521");
    hikariDataSource.setDataSourceProperties(properties);
    //Additionally I am setting connection test query and max life time also
    return hikariDataSource;
}

完整的堆栈跟踪是

Exception in thread "main" java.lang.RuntimeException: Fail-fast during pool initialization
    at com.zaxxer.hikari.pool.HikariPool.fillPool(HikariPool.java:499)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:162)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:113)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:102)
    at java.lang.reflect.Method.invoke(Method.java:597)
Caused by: java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL
    at oracle.jdbc.pool.OracleDataSource.makeURL(OracleDataSource.java:1277)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:185)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
    at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:418)
    at com.zaxxer.hikari.pool.HikariPool.fillPool(HikariPool.java:498)
    ... 11 more

如何建立成功的池?我正在使用 oracle jar http://download.oracle.com/otn/utilities_drivers/jdbc/111070/ojdbc6.jar,jdk 是 1.6。对于 java 6,Hikaricp 版本是 2.2.5。

4

1 回答 1

8

尝试将驱动程序类型设置为thin.

properties.put("driverType", "thin");
于 2015-04-21T09:30:09.057 回答