我在使用https://github.com/impossibl/pgjdbc-ng/连接到 Postgres 数据库时遇到了很大的问题。我需要这个库,因为我需要从数据库中获取异步通知。
我正在尝试使用 SSL 连接到远程数据库,我正在这样做:
Class.forName("com.impossibl.postgres.jdbc.PGDriver");
String url = "jdbc:pgsql://host:5432/db"
+ "?ssl.mode=Require";
Connection conn = DriverManager.getConnection(url, "username", "pwd");
但是,当我尝试这样做时,我得到一个IllegalStateException
. 这是堆栈跟踪:
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
之前,我使用的是标准库org.postgresql.Driver
,一切正常......
有人知道如何帮助我吗?
太感谢了!马可