Hikari DataSource提供Url null异常

时间:2018-03-31 04:16:50

标签: database datasource connection-pooling hsqldb hikaricp

尝试获取Hikari Pool:

final static String DB_URL = "jdbc:hsqldb:hsql://localhost/dbone";
final static String DRIVER = "org.hsqldb.jdbc.JDBCDriver";
final static String DS_DRIVER = "org.hsqldb.jdbc.JDBCDataSource";

public static HikariConfig hikariConfig = new HikariConfig();
public static HikariDataSource hikariDataSource ;
public static HikariConfig getHikariConfig() {
    /*Case 1 : Using ONLY DS_DRIVER */
    hikariConfig.setDataSourceClassName(DS_DRIVER);

    /*Case 2 : using ONLY normal Url for DriverManager*/
    hikariConfig.setJdbcUrl(DB_URL);

    hikariConfig.setMaximumPoolSize(100);
    hikariConfig.setConnectionTimeout(30000);
    hikariConfig.setTransactionIsolation("TRANSACTION_REPEATABLE_READ");
    hikariConfig.setValidationTimeout(5000);

    return hikariConfig;
}

public static HikariDataSource getDataSource(){
    hikariDataSource = new HikariDataSource(getHikariConfig());

    return hikariDataSource;
}

使用静态调用获取连接:

in case(2)ClassName.hikariDataSource.getConnection();我得到了连接

但是在案例1中我得到了这个例外

引起:java.sql.SQLException:JDBC调用中的参数无效:url:null

为什么会这样?

1 个答案:

答案 0 :(得分:0)

如果要按数据源类名使用,则应将数据源属性添加为:

 config.setDataSourceClassName(DS_DRIVER);
 config.addDataSourceProperty("serverName", "localhost");
 config.addDataSourceProperty("port", "1521");
 config.addDataSourceProperty("databaseName", "dbone");
 config.addDataSourceProperty("user", "<yourUser>");
 config.addDataSourceProperty("password", "<yourPassword>");