Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String url = "jdbc:postgresql://localhost:5432/testdb";
- String user = "user12";
- String password = "34klq*";
- try (Connection con = DriverManager.getConnection(url, user, password);
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("SELECT VERSION()")) {
- if (rs.next()) {
- System.out.println(rs.getString(1));
- }
- } catch (SQLException ex) {
- System.out.println("Error: "+ ex);
- Logger lgr = Logger.getLogger(PostgresCommand.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
- }
- abr 06, 2018 8:28:04 AM org.postgresql.core.v3.ConnectionFactoryImpl log
- Error: org.postgresql.util.PSQLException: FATAL: no existe la base de datos «testdb» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
- ADVERTENCIA: SQLException occurred while connecting to localhost:5432
- org.postgresql.util.PSQLException: FATAL: no existe la base de datos «testdb» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
- at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
- at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
- at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
- at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
- at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
- at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
- at org.postgresql.Driver.makeConnection(Driver.java:452)
- at org.postgresql.Driver.connect(Driver.java:254)
- at java.sql.DriverManager.getConnection(DriverManager.java:664)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at database.PostgresCommand.main(PostgresCommand.java:33)
- abr 06, 2018 8:28:04 AM org.postgresql.Driver connect
- GRAVE: Connection error:
- org.postgresql.util.PSQLException: FATAL: no existe la base de datos «testdb» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
- at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
- at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
- at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
- at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
- at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
- at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
- at org.postgresql.Driver.makeConnection(Driver.java:452)
- at org.postgresql.Driver.connect(Driver.java:254)
- at java.sql.DriverManager.getConnection(DriverManager.java:664)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at database.PostgresCommand.main(PostgresCommand.java:33)
- abr 06, 2018 8:28:04 AM database.PostgresCommand main
- GRAVE: FATAL: no existe la base de datos «testdb» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
- org.postgresql.util.PSQLException: FATAL: no existe la base de datos «testdb» (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)
- at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
- at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
- at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
- at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
- at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
- at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
- at org.postgresql.Driver.makeConnection(Driver.java:452)
- at org.postgresql.Driver.connect(Driver.java:254)
- at java.sql.DriverManager.getConnection(DriverManager.java:664)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at database.PostgresCommand.main(PostgresCommand.java:33)
- try{
- ...
- }catch(Exception e)
- {
- //Puedes investigar los métodos de e para obtener información
- }
Add Comment
Please, Sign In to add comment