Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';使用ElephantSQL在Bluemix中部署Liberty应用程序时找不到有效的JDBC驱动程序_Java_Postgresql_Jdbc_Ibm Cloud_Websphere Liberty - Fatal编程技术网

Java Can';使用ElephantSQL在Bluemix中部署Liberty应用程序时找不到有效的JDBC驱动程序

Java Can';使用ElephantSQL在Bluemix中部署Liberty应用程序时找不到有效的JDBC驱动程序,java,postgresql,jdbc,ibm-cloud,websphere-liberty,Java,Postgresql,Jdbc,Ibm Cloud,Websphere Liberty,我有一个WebSphereLiberty 16.0.0.2WebApp,我用DerbyDB开发并在笔记本电脑上本地运行,使用JPA处理数据库。我曾经使用SQLDB将其部署到Bluemix中(IBM于2016年5月将其退役),通过服务的自动连接,一切都很好。由于SQLDB不再可用,我在Bluemix上找到的唯一免费SQL是ElephantSQL,但是自动连接似乎不起作用。以下是部署后出现的错误: Program error occured: CWWJP0013E: The server canno

我有一个WebSphereLiberty 16.0.0.2WebApp,我用DerbyDB开发并在笔记本电脑上本地运行,使用JPA处理数据库。我曾经使用SQLDB将其部署到Bluemix中(IBM于2016年5月将其退役),通过服务的自动连接,一切都很好。由于SQLDB不再可用,我在Bluemix上找到的唯一免费SQL是ElephantSQL,但是自动连接似乎不起作用。以下是部署后出现的错误:

Program error occured: CWWJP0013E: The server cannot locate the java:comp/env/jdbc/TriReplicatorDB data source for the TriReplicatorPersistenceUnit persistence unit because it has encountered the following exception: javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/jdbc/TriReplicatorDB JNDI name could not be instantiated. If the reference name maps to a JNDI name in the deployment descriptor bindings for the application performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context. [Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/jdbc/TriReplicatorDB reference. The exception message was: CWNEN1006E: The server was unable to obtain an object for the jdbc/TriReplicatorDB binding with the javax.sql.DataSource type. The exception message was: java.sql.SQLNonTransientException: DSRA4000E: A valid JDBC driver implementation class was not found for the jdbcDriver jdbcDriver[myDerbyJDBCdriver] using the library com.ibm.ws.classloading.sharedlibrary_79. [/home/vcap/app/wlp/usr/servers/triServer/lib/postgresql-jdbc-9.4.1209.jar]]. 
我上传web应用的方式是打包服务器并使用
cf push
命令。以下是生成的server.xml文件:

<server description="new server">
<!-- Enable features -->
<featureManager>
    <feature>jsp-2.3</feature>
    <feature>concurrent-1.0</feature>
    <feature>jaxrs-2.0</feature>
    <feature>jaxrsClient-2.0</feature>
    <feature>jpa-2.1</feature>
    <feature>appSecurity-2.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>icap:managementConnector-1.0</feature>
    <feature>appstate-1.0</feature>
    <feature>jdbc-4.1</feature>
    <feature>cloudAutowiring-1.0</feature>
</featureManager>
<httpEndpoint httpPort="${port}" id="defaultHttpEndpoint" host="*"/>
<webContainer deferServletLoad="false" trustHostHeaderPort="true" extractHostHeaderPort="true"/>
<applicationMonitor updateTrigger="mbean"/>
<!-- This is the application itself -->
<webApplication contextRoot="/" id="Tri-Replicator" location="Tri-Replicator.war" name="Tri-Replicator">
</webApplication>
<jdbcDriver id="myDerbyJDBCdriver">
    <library name="DerbyLib">
        <fileset dir="C:\projects_c\Tri-Replicator-16\db\db-derby-10.11.1.1-bin\lib" includes="derby.jar"/>
        <fileset dir='${server.config.dir}/lib' includes='postgresql-jdbc-9.4.1209.jar'/>
    </library>
</jdbcDriver>
<!-- Use local Derby DB for local testing on laptop, but when deployed into BlueMix this will automatically be rewired to use SQL DB instance -->
<dataSource id="DerbyConnection" jdbcDriverRef="myDerbyJDBCdriver" jndiName="jdbc/TriReplicatorDB">
    <properties createDatabase="create" databaseName="${cloud.services.ElephantSQL-tri-replicator.connection.name}" user="${cloud.services.ElephantSQL-tri-replicator.connection.user}" password="${cloud.services.ElephantSQL-tri-replicator.connection.password}" serverName="${cloud.services.ElephantSQL-tri-replicator.connection.host}" portNumber="${cloud.services.ElephantSQL-tri-replicator.connection.port}"/>
</dataSource>
<include location='runtime-vars.xml'/>
<httpDispatcher enableWelcomePage='false'/>
<config updateTrigger='mbean'/>
<appstate appName='Tri-Replicator' markerPath='${home}/../.liberty.state'/>

jsp-2.3
并发-1.0
jaxrs-2.0
jaxrsClient-2.0
jpa-2.1
appSecurity-2.0
localConnector-1.0
icap:managementConnector-1.0
appstate-1.0
jdbc-4.1
cloudAutowiring-1.0


另一个问题是,有人能为Bluemix中的SQL数据库推荐其他小型免费计划吗?PostgreSQL和DB2不提供免费计划。

报告的异常情况说明如下:

A valid JDBC driver implementation class was not found 
for the jdbcDriver jdbcDriver[myDerbyJDBCdriver]
org.postgresql.ds.PGPoolingDataSource
javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource"
此异常表示无法在
postgresql-jdbc-9.4.1209.jar
中找到连接池数据源类

WLP按设计工作,需要在server.xml中进行额外配置,因为WLP只能定位特定数量的已知数据库的实现类[1]。我查看了
postgresql-jdbc-9.4.1209.jar
驱动程序,发现实现类如下所示:

A valid JDBC driver implementation class was not found 
for the jdbcDriver jdbcDriver[myDerbyJDBCdriver]
org.postgresql.ds.PGPoolingDataSource
javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource"
应使用以下内容更新server.xml文件:

A valid JDBC driver implementation class was not found 
for the jdbcDriver jdbcDriver[myDerbyJDBCdriver]
org.postgresql.ds.PGPoolingDataSource
javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource"
[1]

要使用PostgreSQL(ElephantSQL使用的JDBC驱动程序),您需要在
元素上指定数据源实现类名:

<jdbcDriver id="myDerbyJDBCdriver" javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource">
  <!-- keep nested stuff the same -->
</jdbcDriver>

您需要为PostgreSQL而不是Derby指定DataSource impl类的原因是,Derby是Liberty的“已知”数据库,而不是PostgreSQL


我会让Liberty development知道这一点,以便将来某个时候可以将PostgreSQL添加为“已知”数据库。

org.PostgreSQL.ds.pgpoolgDataSource
不实现
javax.sql.XADataSource
,因此,我不建议将Xadasource实现设置为不实现Xadasource的类。还有其他属性,如
javax.sql.DataSource
javax.sql.ConnectionPoolDataSource
,可以替代使用。这是非常正确的,我犯了一个错误。PostgreSQL驱动程序没有XA数据源类。我已经更新了答案以反映变化。谢谢你,阿奎伯特!感谢您的快速响应-它现在可以工作了,只是现在我必须在将应用程序推送到Bluemix之前手动更改server.xml,因为当我有这个指向Postgres JDBC驱动程序的额外指针时,我的本地Derby数据库JDBC驱动程序无法正确加载:
。。。至于JPA代码——我现在正在修复数据库访问问题,因为我与Derby和DB2一起工作的代码不再与Postgres一起工作,但这是另一个主题……结果是jar文件postgresql-jdbc-9.4.1209.jar中有一个XA驱动程序,由Bluemix自动添加到应用程序部署中,下面是我现在使用的:
。这里描述了这个驱动程序:我在前面的评论中提到,使用XA驱动程序可以连接到数据库,但是从来没有创建过表。根据您先前的建议,我使用了非XA驱动程序来修复它:
这里发生的事情是Liberty buildpack在server.xml上执行了自动配置,并添加了正确的JDBC驱动程序,但忘记了用正确的
javax.sql.dataSource
属性更新
数据源
元素。那看起来像个虫子。请在中报告此问题。我确实将此作为新问题提交: