0
votes

I'm using wso2ei and created a scheduled job from a carbon application. The issue I'm facing is that after wso2 restart that job fails to connect to a local postgresql db with the following error:

TID: [-1] [] [2018-07-04 22:09:17,319] ERROR {org.wso2.carbon.ntask.core.impl.TaskQuartzJobAdapter} -  Error in executing task: null {org.wso2.carbon.ntask.core.impl.TaskQuartzJobAdapter}
java.lang.ExceptionInInitializerError
...
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
...
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling DriverManager#getConnection
...
Caused by: java.sql.SQLException: No suitable driver found for jdbc:postgresql://127.0.0.1:5432/dbanme

I have copied the postgresql jar file in all the following dirs (first and last one copied automatically on restart).

# find ./* -name 'postgresql*.jar'
./dropins/postgresql_42.1.4_1.0.0.jar
./lib/endorsed/postgresql-42.1.4.jar
./lib/postgresql-42.1.4.jar
./repository/axis2/client/lib/postgresql-42.1.4.jar
./repository/components/lib/postgresql-42.1.4.jar
./samples/axis2Client/lib/postgresql-42.1.4.jar
./wso2/broker/repository/lib/postgresql-42.1.4.jar
./wso2/components/plugins/postgresql-42.1.4.jar
./wso2/components/default/configuration/org.eclipse.osgi/bundles/619/1/.cp/postgresql-42.1.4.jar

One thing that fixes the issue is when going in Home > Configure > Datasources, edit a custom datasource, hit Test connection and everything goes back to normality and there are no errors anymore, connections work from everywhere.

Is there a specific place where the jar file should be placed?

1
Looks like a class loading issue. Are you creating this database connection from some custom code? - Bee
Yes, the connections is made in the carbon app (scheduler), however that works too after the "test connection" is triggered manually in wso2 admin console as described above. - Altin Ukshini
Connection is made inside a java code? - Bee
Yes that's right! - Altin Ukshini
Can you share the code? - Bee

1 Answers

0
votes

In general, when you configure the WSO2 datasources or develop a data service, you have to place the jdbc drivers only in the /lib folder. When you start the server the jar is repacked in a osgi bundle and copied in the /dropins folder. So try to delete all the jars you put previously and copy the correct one to the lib folder and try to start the server.