对于informix,目标类com.informix.jdbcx.IfxDataSource上不存在赋予IFXHOST的Hikari连接池

时间:2017-06-19 14:24:09

标签: datasource connection-pooling informix hikaricp

我在informix版本4.10.6.20151104中使用此属性

    spring.informix.datasource.type=com.zaxxer.hikari.HikariDataSource
 spring.informix.datasource.dataSourceClassName=com.informix.jdbcx.IfxDataSource
      spring.informix.datasource.dataSourceProperties.serverName=CISCO-UCCE-EXP
      spring.informix.datasource.dataSourceProperties.portNumber=1504
     spring.informix.datasource.dbcp2.pool-prepared-statements=true
    spring.informix.datasource.dataSourceProperties.IFXHOST = cisco_ucce_exp_uccx

收到错误

java.lang.RuntimeException: Property IFXHOST does not exist on target class com.informix.jdbcx.IfxDataSource
    at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:155) ~[HikariCP-2.4.7.jar:na]
    at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:67) ~[HikariCP-2.4.7.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:295) ~[HikariCP-2.4.7.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:91) ~[HikariCP-2.4.7.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:101) ~[HikariCP-2.4.7.jar:na]
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94) ~[HikariCP-2.4.7.jar:na]
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) ~[spring-jdbc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) ~[spring-jdbc-4.3.3.RELEASE.jar:4.3.3.RELEASE]

我也尝试过相同的配置 https://docs.oracle.com/cd/E19575-01/821-0185/beanj/index.html 对于IfxIFXHost,我也遇到了同样的问题 善意的帮助。 P.S我是Hikari的新手

2 个答案:

答案 0 :(得分:4)

之前从未使用过Hikari,但是快速测试会显示您应该添加到数据源以获取连接的属性:

使用&#34; IFXHOST&#34;我得到了例外:

D:\JJTMP>grep IFXHOST p.java
                                                config.addDataSourceProperty("IFXHOST", "420ito");
                                                config.addDataSourceProperty("IfxIFXHOST", "420ito");

D:\JJTMP>java p
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] ERROR com.zaxxer.hikari.util.PropertyElf - Property IFXHOST does not exist on target class com.informix.jdbcx.IfxDataSource
Exception in thread "main" java.lang.NullPointerException
        at p.main(p.java:64)

使用&#34; IfxIFXHOST&#34;工作原理:

D:\JJTMP>grep IFXHOST p.java
                                                //config.addDataSourceProperty("IFXHOST", "420ito");
                                                config.addDataSourceProperty("IfxIFXHOST", "420ito");

D:\JJTMP>javac p.java

D:\JJTMP>java p
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] INFO com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (M
ethod not supported : IfxSqliConnect.getNetworkTimeout())
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
The Connection Object is of Class: class com.zaxxer.hikari.pool.HikariProxyConnection
systables,informix                        ,1048580
syscolumns,informix                        ,1048581
sysindices,informix                        ,1048582
systabauth,informix                        ,1048583
syscolauth,informix                        ,1048584

D:\JJTMP>

以防万一,我正在使用的代码:

// ----- p.java -----
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

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

public class p
{

        private static DataSource datasource;

        public static DataSource getDataSource()
        {
                if(datasource == null)
                {
                        HikariConfig config = new HikariConfig();

                        config.setDataSourceClassName("com.informix.jdbcx.IfxDataSource");
                        config.addDataSourceProperty("serverName", "ids1210");
                        //config.addDataSourceProperty("IFXHOST", "420ito");
                        config.addDataSourceProperty("IfxIFXHOST", "420ito");
                        config.addDataSourceProperty("PortNumber", "9088");
                        config.addDataSourceProperty("databaseName", "sysmaster");
                        config.addDataSourceProperty("user", "informix");
                        config.addDataSourceProperty("password", "ximrofni");
                        config.setMaximumPoolSize(10);
                        config.setAutoCommit(false);

                        datasource = new HikariDataSource(config);
                }
                return datasource;
        }

        public static void main(String[] args)
        {

                Connection connection = null;
                PreparedStatement pstmt = null;
                ResultSet resultSet = null;
                try
                {
                        DataSource dataSource = p.getDataSource();
                        connection = dataSource.getConnection();
                        pstmt = connection.prepareStatement("SELECT FIRST 5 * FROM systables");

                        System.out.println("The Connection Object is of Class: " + connection.getClass());

                        resultSet = pstmt.executeQuery();
                        while (resultSet.next())
                        {
                                System.out.println(resultSet.getString(1) + "," + resultSet.getString(2) + "," + resultSet.getString(3));
                        }

                }
                catch (Exception e)
                {
                        try
                        {
                                connection.rollback();
                        }
                        catch (SQLException e1)
                        {
                                e1.printStackTrace();
                        }
                        e.printStackTrace();
                }

        }

}

// ----- p.java -----

答案 1 :(得分:0)

所以这对我有用

spring.informix.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.informix.datasource.minimumIdle=10
spring.informix.datasource.maximumPoolSize=30
spring.informix.datasource.idleTimeout=500
spring.informix.datasource.dataSourceClassName=com.informix.jdbcx.IfxDataSource
spring.informix.datasource.dataSourceProperties.databaseName=db_
spring.informix.datasource.dataSourceProperties.serverName=CISCO-UCCE-EXP
#spring.informix.datasource.dataSourceProperties.url = jdbc:informix-sqli://CISCO-UCCE-EXP:1504/db_cra:INFORMIXSERVER=cisco_ucce_exp_uccx; Protocol=onsoctcp; client_locale=en_US.57372; db_locale=en_US.57372
spring.informix.datasource.dataSourceProperties.portNumber=1504
spring.informix.datasource.dbcp2.pool-prepared-statements=true
spring.informix.datasource.dataSourceProperties.LoginTimeout=0
spring.informix.datasource.connectionTimeout=0
spring.informix.datasource.dataSourceProperties.IfxIFXHOST=cisco_ucce_exp_uccx