Guest User

Untitled

a guest
Apr 6th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. String url = "jdbc:postgresql://localhost:5432/testdb";
  4. String user = "user12";
  5. String password = "34klq*";
  6.  
  7. try (Connection con = DriverManager.getConnection(url, user, password);
  8. Statement st = con.createStatement();
  9. ResultSet rs = st.executeQuery("SELECT VERSION()")) {
  10.  
  11. if (rs.next()) {
  12. System.out.println(rs.getString(1));
  13. }
  14.  
  15. } catch (SQLException ex) {
  16.  
  17. System.out.println("Error: "+ ex);
  18. Logger lgr = Logger.getLogger(PostgresCommand.class.getName());
  19. lgr.log(Level.SEVERE, ex.getMessage(), ex);
  20. }
  21. }
  22.  
  23. abr 06, 2018 8:28:04 AM org.postgresql.core.v3.ConnectionFactoryImpl log
  24. 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)
  25. ADVERTENCIA: SQLException occurred while connecting to localhost:5432
  26. 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)
  27. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
  28. at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
  29. at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
  30. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
  31. at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
  32. at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
  33. at org.postgresql.Driver.makeConnection(Driver.java:452)
  34. at org.postgresql.Driver.connect(Driver.java:254)
  35. at java.sql.DriverManager.getConnection(DriverManager.java:664)
  36. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  37. at database.PostgresCommand.main(PostgresCommand.java:33)
  38.  
  39. abr 06, 2018 8:28:04 AM org.postgresql.Driver connect
  40. GRAVE: Connection error:
  41. 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)
  42. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
  43. at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
  44. at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
  45. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
  46. at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
  47. at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
  48. at org.postgresql.Driver.makeConnection(Driver.java:452)
  49. at org.postgresql.Driver.connect(Driver.java:254)
  50. at java.sql.DriverManager.getConnection(DriverManager.java:664)
  51. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  52. at database.PostgresCommand.main(PostgresCommand.java:33)
  53.  
  54. abr 06, 2018 8:28:04 AM database.PostgresCommand main
  55. 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)
  56. 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)
  57. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
  58. at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2566)
  59. at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:131)
  60. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:210)
  61. at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
  62. at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
  63. at org.postgresql.Driver.makeConnection(Driver.java:452)
  64. at org.postgresql.Driver.connect(Driver.java:254)
  65. at java.sql.DriverManager.getConnection(DriverManager.java:664)
  66. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  67. at database.PostgresCommand.main(PostgresCommand.java:33)
  68.  
  69. try{
  70. ...
  71. }catch(Exception e)
  72. {
  73. //Puedes investigar los métodos de e para obtener información
  74. }
Add Comment
Please, Sign In to add comment