2

I'm having a weird problem with my app trying to connect to PostgreSQL with Jdbc driver version: 8.4-702.jdbc4

It seems it can't find the DB defined in the persistence.xml where it's there.

Error:

[INFO] Caused by: org.postgresql.util.PSQLException: FATAL: database "mydb" does not exist
[INFO]  at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:464)
[INFO]  at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
[INFO]  at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
[INFO]  at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
[INFO]  at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
[INFO]  at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
[INFO]  at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
[INFO]  at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
[INFO]  at org.postgresql.Driver.makeConnection(Driver.java:393)
[INFO]  at org.postgresql.Driver.connect(Driver.java:267)
[INFO]  at java.sql.DriverManager.getConnection(DriverManager.java:579)
[INFO]  at java.sql.DriverManager.getConnection(DriverManager.java:221)
[INFO]  at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:89)
[INFO]  at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:72)
[INFO]  at org.apache.shiro.realm.jdbc.JdbcRealm.doGetAuthenticationInfo(JdbcRealm.java:215

However I can do this w/o problems in the shell:

$ psql -U postgres -h 192.168.145.128

persistence.xml

  <properties>
     <property name="hibernate.hbm2ddl.auto" value="update"/>
     <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.145.128:5432/mydb" />
     <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
     <property name="javax.persistence.jdbc.user" value="postgres" /> 
     <property name="javax.persistence.jdbc.password" value="postgres" /> 
  </properties>

What could be the problem?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
quarks
  • 33,478
  • 73
  • 290
  • 513
  • 1
    Your psql command tells nothing about "mydb" - it just connects to the default DB. Try to connect to mydb or see if it's there (I suppose that was "\l", have no Postgresql here) – Gyro Gearless May 28 '13 at 08:15
  • Your persistence.xml file suggests the database it should be connecting to is called magick, but your STDERR suggests it's trying to connect to a database called mydb. Unless you purposely changed that in the copy/paste, it doesn't seem like it's even using that configuration. – Hassan Shahid Jun 18 '13 at 22:05

1 Answers1

0

In my case it was because of wrong username and password given.

Kundan Atre
  • 3,853
  • 5
  • 26
  • 39