DB2 异常:无法创建 PoolableConnectionFactory SQLCODE=-142,

DB2 exception: Cannot create PoolableConnectionFactory SQLCODE=-142,

我在 MobileFirst Platform 6.3 中一直出现以下错误:

Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (DB2 SQL Error: SQLCODE=-142, SQLSTATE=42612, SQLERRMC=null, DRIVER=4.19.26)

这是我的适配器代码:

     var test2 = WL.Server.createSQLStatement("SELECT * FROM WSDIWC.WBPTRR1");

     function getCEID(cnum) {   
        return WL.Server.invokeSQLStatement({
            preparedStatement : test2,
            parameters : []
        });
     }

和适配器 XML:

     <connectivity>
        <connectionPolicy xsi:type="sql:SQLConnectionPolicy">
        <!-- Example for using a JNDI data source, replace with actual data source 
            name -->
        <!-- <dataSourceJNDIName>${training-jndi-name}</dataSourceJNDIName> -->

        <!-- Example for using MySQL connector, do not forget to put the MySQL 
            connector library in the project's lib folder -->
         <dataSourceDefinition>
              <driverClass>com.ibm.db2.jcc.DB2Driver</driverClass>
               <url>jdbc:db2://***</url>
               <user>**</user>
                <password>**</password>
            </dataSourceDefinition>
        </connectionPolicy>
    </connectivity>

我已经删除了 url、用户和密码。 希望你帮我澄清一下当前的问题。

我已经知道 sql 不被接受,因为它只是一个简单的查询。
我还研究了 z/OS DB2,它有相同错误代码 sqlcode=-142 的问题。 http://answers.splunk.com/answers/117024/splunk-db-connect-db2.html

虽然你说这是 "simple query",the exception error code mentions the following:

-142
THE SQL STATEMENT IS NOT SUPPORTED

Explanation

An SQL statement was detected that is not supported by the database. The statement might be valid for other IBM® relational database products or it might be valid in another context. For example, statements such as VALUES and SIGNAL or RESIGNAL SQLSTATE can be used only in certain contexts, such as in a trigger body or in an SQL Procedure.

System action
The statement cannot be processed.

Programmer response
Change the syntax of the SQL statement or remove the statement from the program.

您应该查看有关如何实现您想要实现的目标的 DB2 SQL 指南,如果您需要进一步的帮助,还应在问题中进行解释。例如,您确定 "WSDIWC.WBPTRR1" 实际上可用吗?

我在 JDBC 连接到 MobileFirst 6.3 中的大型机 DB2 时遇到了同样的问题。与 DB2 LUW 的连接工作正常。似乎默认池 validationQuery 对 DB2 LUW 有效,但对 DB2 无效 z/OS.

您可以通过在 Liberty 配置文件中配置数据源来解决该错误 server.xml。在 Eclipse Servers 视图中,展开 MobileFirst Development Server 并编辑 Server Configuration。在那里添加驱动程序和数据源;例如:

 <library id="db2jcc">
    <fileset dir="whereever" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
 </library>
 <dataSource id="db2" jndiName="jdbc/db2">
    <jdbcDriver libraryRef="db2jcc"/>
    <properties.db2.jcc databaseName="mydb" portNumber="5021" 
        serverName="myserver" user="myuser" password="mypw" />
 </dataSource>

然后在您的适配器 XML 中引用它 connectionPolicy:

 <dataSourceJNDIName>jdbc/db2</dataSourceJNDIName> 

在 server.xml(与适配器 XML 相比)中配置数据源的一个好处是您可以访问所有数据源、JDBC 和 JCC 属性。所以如果连接池给你带来其他问题,你可以自定义或者切换到其他数据源类型,比如type="javax.sql.DataSource".