Java – no suitable driver Try using hibernate to connect to the PostgreSQL database on heroku
I'm sorry to bother you, but I've been receiving errors. I don't understand why
As specified in the title, I'm trying to connect to the PostgreSQL database running heroku using hibernate My application also runs on heroku
It works in local mode, and I tried several Postgres drivers
This is 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>
When I receive a session, I will overwrite the web address, password and user name:
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 was found I'm sure the URL is OK (if I try another URL, I'll get a connection error)
Here I rely on:
<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>
They are exported as described in my POM (I can see Maven copying my application when it is deployed):
<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 I can't see what I did wrong at this point:/
This is the error log I got:
Thank you for your time!
Solution
There are some suspicious things about your database web address:
Decomposition:
>JDBC scheme: PostgreSQL – OK > hostname: paafeblgkhhbkx – suspicious > port: phzethl2rhwbwdqjjourmej89-@ec2-54-243-243-252 compute-1. amazonaws. COM – absolutely wrong
You obviously tried to include the username and password as part of the connection URL, but that's not how it's done These are configured with separate properties. If you want to include them in the URI, do the following:
JDBC: in PostgreSQL: / / local host / test user = Fred's & amp; Password = secret?
As a side note, I have successfully connected to your database, so in addition to the correct host name, I can also prove the correctness of your credentials disclosed to the public It's time to change the password