I'm facing a great problem in connecting to a Postgres database using https://github.com/impossibl/pgjdbc-ng/. I need this lib because I need to get asynchronous notification from the database.
I'm trying to connect to a remote database using SSL an I'm 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 that I get an 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
Before, I was using the standard library org.postgresql.Driver
and everything worked fine...
Does anybody know how to help me?
Thank you so much! Marco