There is no suitable driver. Trying to connect to postgresql database on Heroku using Hibernate

Sorry to bother you, but I keep getting the error and I really don't understand why.

As the title says, I am trying to connect to my postgresql database using hero using hibernate. My app is also running on Heroku.

It works in local mode, I tried several postgre drivers.

Here's my hibernate.cfg.xml:

<!-- PostgreSQL -->

<property name="connection.url">jdbc:postgresql://paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq</property>

<property name="connection.username">paafeblgkhhbk</property>

<property name="connection.password">My password</property>

<property name="connection.driver_class">org.postgresql.Driver</property>

<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

<!-- Disable the second-level cache  -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

      

The url, password and username are overridden when I get the session:

Configuration configuration = new Configuration();
configuration.addAnnotatedClass(Client.class);
// and other classes

try {  
    Class.forName("org.postgresql.Driver"); 
    System.out.println(" === === DRIVER FOUND === === ");   
} catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.out.println(" === === DRIVER NOT FOUND === === ");
}
configuration.configure();
System.out.println("============================= EXPORT SCHEMA ==========================");
new SchemaExport(configuration).create(true, true);
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

      

As you can see, the driver has been found. I'm sure the url is ok too (if I try with another, I get a connection error)

Here's my settings:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.9.Final</version>
</dependency>
<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901.jdbc4</version>
</dependency>

      

And they are exported as mentioned here in my pom (I can see maven copying it when I deploy my application):

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
    <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals><goal>copy-dependencies</goal></goals>
    </execution>
</executions>
</plugin>

      

So at this point I can't see what I did wrong: /

Here is the error log I receive:

Run with command java -cp target/classes:target/dependency/* test.Server

State changed from start to

org.hibernate.annotations.common.Version

INFO: HCANN000001: hibernation annotations {4.0.1.Final}

org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.1.9.Final}

org.hibernate.cfg.Environment

INFO: HHH000206: hibernate.properties not found

org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: bytecode provider name: javassist

org.hibernate.cfg. Config configuration

INFO: HHH000043: setting from resource: /hibernate.cfg.xml

org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: config resource: /hibernate.cfg.xml

org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

=== === DRIVER FOUND === ===

============================ EXPORT SCHEME ================ ===== =====

org.hibernate.dialect.Dialect

INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect

org.hibernate.tool.hbm2ddl.SchemaExport execute

INFO: HHH000227: start hbm2ddl schema export

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Setting

INFO: HHH000402: using Hibernate's built-in connection pooling (not for production use!)

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Setting

INFO: HHH000115: Hibernation connection pool size: 2

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Setting

INFO: HHH000006: autosave mode: false

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Setting

INFO: HHH000401: Using driver [org.postgresql.Driver] at url [JDBC: PostgreSQL: // paafeblgkhhbkx: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaw s.com: d1vsgjgnfr1koq]

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl Setting

INFO: HHH000046: Connection Properties: {user = paafeblgkhhbkx, password = **}

org.hibernate.tool.hbm2ddl.SchemaExport execute

ERROR: HHH000231: schema export failed

java.sql.SQLException: No suitable driver found for JDBC: PostgreSQL: // paafeblgkhhbkx: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaw s.com: 5432 / d1vsqjgnfr1

at java.sql.DriverManager.getConnection (DriverManager.java:640)

at java.sql.DriverManager.getConnection (DriverManager.java:169)

at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection (DriverManagerConnectionProviderImpl.java:193)

at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare (ManagedProviderConnectionHelper.java:55)

in org.hibernate.tool.hbm2ddl.DatabaseExporter. (DatabaseExporter.java:52)

at org.hibernate.tool.hbm2ddl.SchemaExport.execute (SchemaExport.java:367)

at org.hibernate.tool.hbm2ddl.SchemaExport.create (SchemaExport.java:304)

at org.hibernate.tool.hbm2ddl.SchemaExport.create (SchemaExport.java:293)

at persistance.SessionFactorySingleton.configureSessionFactory (SessionFactorySingleton.java:36)

at persistance.SessionFactorySingleton.getSessionFactory (SessionFactorySingleton.java:61)

at persistance.Controller.beginSession (Controller.java:24)

at persistance.Controller.sauvegarde (Controller.java:36)

at persistance.Controller.save (Controller.java:51)

at test.Server $ 1.handle (Server.java:44)

at com.sun.net.httpserver.Filter $ Chain.doFilter (Filter.java:83)

at sun.net.httpserver.AuthFilter.doFilter (AuthFilter.java:83)

at com.sun.net.httpserver.Filter $ Chain.doFilter (Filter.java:86)

at sun.net.httpserver.ServerImpl $ Exchange $ LinkHandler.handle (ServerImpl.java:589)

at com.sun.net.httpserver.Filter $ Chain.doFilter (Filter.java:83)

at sun.net.httpserver.ServerImpl $ Exchange.run (ServerImpl.java:561)

at sun.net.httpserver.ServerImpl $ DefaultExecutor.execute (ServerImpl.java:137)

at sun.net.httpserver.ServerImpl $ Dispatcher.handle (ServerImpl.java:367)

at sun.net.httpserver.ServerImpl $ Dispatcher.run (ServerImpl.java:339)

at java.lang.Thread.run (Thread.java:679)

Thank you for your time!

+3


source to share


1 answer


There is something rather fishy about your database URL:

JDBC: PostgreSQL: // paafeblgkhhbkx: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaw s.com: 5432 / d1vsgjgnfr1koq

Structure:

  • JDBC Schema: postgresql

    - OK
  • hostname: paafeblgkhhbkx

    - suspicious
  • port: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com

    - definitely wrong.


It looks like you are trying to include the username and password as part of the connection url, but that is not how it is done. They are configured using separate properties, and if you, include them in the URI, do the following:

jdbc:postgresql://localhost/test?user=fred&password=secret


As a side note, I have successfully connected to your database so that I can confirm that the credentials you have exposed to the public are correct, in addition to the correct hostname. Time to change this password ...

+7


source







All Articles