PGPoolingDataSource dataSource_pg = new PGPoolingDataSource();;
dataSource_pg.setServerName("192.168.1.12");
dataSource_pg.setDatabaseName("atcdb");
dataSource_pg.setUser("klia");
dataSource_pg.setPassword("klia01");
try{
Connection connection = dataSource_pg.getConnection();
}catch(SQLException ex){
System.out.println("Error");
}
Nel codice di sopra mi aspetterei che se la connessione al DB non è possibile, io riceva l'eccezione nel catch. Invece quando arriva al catch, viene inviata a console la seguente stacktrace:
mag 29, 2017 4:19:36 PM org.postgresql.Driver connect
GRAVE: Connection error:
org.postgresql.util.PSQLException: Connection to 192.168.1.12:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:431)
at org.postgresql.Driver.connect(Driver.java:247)
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:79)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:64)
at org.postgresql.ds.PGConnectionPoolDataSource.getPooledConnection(PGConnectionPoolDataSource.java:58)
at org.postgresql.ds.PGPoolingDataSource.getPooledConnection(PGPoolingDataSource.java:381)
at org.postgresql.ds.PGPoolingDataSource.getConnection(PGPoolingDataSource.java:326)
at Main.main(Main.java:70)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
... 12 more
ora, siccome ho gestito il catch per scrivere solo "ERROR", come mai trovo tutto lo stacktrace in console?