SSL connection using pgjdbc-ng as Java driver for Postgres

I ran into a big problem while connecting to Postgres database using https://github.com/impossibl/pgjdbc-ng/ . I need this lib because I need to receive an asynchronous notification from the database.

I am trying to connect to a remote database using SSL and I am doing this:

Class.forName("com.impossibl.postgres.jdbc.PGDriver");

String url = "jdbc:pgsql://host:5432/db"
                        + "?ssl.mode=Require";
Connection conn = DriverManager.getConnection(url, "username", "pwd");

      

But, when I try to do this, I get IllegalStateException

. This is the stack trace:

java.sql.SQLException: Connection Error: java.lang.IllegalStateException
 at com.impossibl.postgres.jdbc.ConnectionUtil.createConnection(ConnectionUtil.java:189)
 at com.impossibl.postgres.jdbc.PGDriver.connect(PGDriver.java:77)
 at com.impossibl.postgres.jdbc.PGDriver.connect(PGDriver.java:52)
 at java.sql.DriverManager.getConnection(DriverManager.java:179)
 at it.polito.mobile.testpostgres.MainActivity$1.doInBackground(MainActivity.java:60)
 at it.polito.mobile.testpostgres.MainActivity$1.doInBackground(MainActivity.java:35)
 at android.os.AsyncTask$2.call(AsyncTask.java:288)
 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 at java.lang.Thread.run(Thread.java:818)
 Caused by: java.io.IOException: java.lang.IllegalStateException
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.translateConnectionException(ProtocolFactoryImpl.java:285)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:199)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:90)
 at com.impossibl.postgres.system.BasicContext.<init>(BasicContext.java:130)
 at com.impossibl.postgres.jdbc.PGConnectionImpl.<init>(PGConnectionImpl.java:185)
 at com.impossibl.postgres.jdbc.ConnectionUtil.createConnection(ConnectionUtil.java:180)
 ... 11 more
 Caused by: java.lang.IllegalStateException
 at io.netty.handler.ssl.SslHandler$LazyChannelPromise.executor(SslHandler.java:1491)
 at io.netty.util.concurrent.DefaultPromise.checkDeadLock(DefaultPromise.java:388)
 at io.netty.util.concurrent.DefaultPromise.awaitUninterruptibly(DefaultPromise.java:283)
 at io.netty.util.concurrent.DefaultPromise.syncUninterruptibly(DefaultPromise.java:225)
 at io.netty.util.concurrent.DefaultPromise.syncUninterruptibly(DefaultPromise.java:32)
 at com.impossibl.postgres.protocol.v30.ProtocolFactoryImpl.connect(ProtocolFactoryImpl.java:132)
 ... 15 more

      

I used to use the standard library org.postgresql.Driver

and everything worked fine ...

Does anyone know how to help me?

Thank you very much! Marco

+3


source to share





All Articles