Unable to connect to PostgreSQL JDBC DataSource Blueprint

Problem Description

When adding a PostgreSQL JDBC DataSource Blueprint using the template <path>\esb\add-ons\datasources\dataservice\datasource-postgres.xml, the connection fails as shown in the error stack trace below:

Exception in component tDBConnection_3 (testpg)
org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
        at org.postgresql.jdbc.PgConnection.(PgConnection.java:216)
        at org.postgresql.Driver.makeConnection(Driver.java:406)
        at org.postgresql.Driver.connect(Driver.java:274)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:87)
        at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:72)
        at org.postgresql.ds.PGConnectionPoolDataSource.getPooledConnection(PGConnectionPoolDataSource.java:61)
        at org.postgresql.ds.PGPoolingDataSource.initialize(PGPoolingDataSource.java:274)
        at org.postgresql.ds.PGPoolingDataSource.getConnection(PGPoolingDataSource.java:324)
        at Proxy0975ee08_03f5_46d0_bfe1_cfe13ceaaf50.getConnection(Unknown Source)
        at routines.system.TalendDataSource.getConnection(TalendDataSource.java:26)
        at local.testpg_0_1.testpg.tDBConnection_3Process(testpg.java:2573)
        at local.testpg_0_1.testpg.tPrejob_1Process(testpg.java:2383)
        at local.testpg_0_1.testpg.runJobInTOS(testpg.java:3759)
        at org.talend.esb.job.controller.internal.SimpleJobTask$JobRunner.run(SimpleJobTask.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at org.talend.esb.job.controller.internal.SimpleJobTask.run(SimpleJobTask.java:63)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

 

Root Cause

 

Solution

Add a ? after the database name in the serverName attribute, as shown in the example below:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
 
   <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
      <property name="serverName" value="localhost:5432/testdb?"/>
      <property name="user" value="MM"/>
      <property name="password" value="MM"/>
      <property name="dataSourceName" value="conPoolTld_ESB_1"/>
      <property name="initialConnections" value="2"/>
      <property name="maxConnections" value="6" />
  </bean>
 
  <service interface="javax.sql.DataSource" ref="dataSource">
    <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/tld"/>
    </service-properties>
  </service>
 
</blueprint>
Version history
Revision #:
9 of 9
Last update:
‎07-05-2019 04:03 AM
Updated by: