没有合适的驱动程序。尝试使用Hibernate连接到Heroku上的postgresql数据库 [英] No suitable driver. Trying to connect to a postgresql database on Heroku using Hibernate
问题描述
很抱歉打扰你,但我一直收到一个错误,我不明白为什么。
正如标题中所指定的,我试图连接到我的使用hibernate运行heroku的postgresql数据库。我的应用程序也在Heroku上运行。
它以本地模式工作,我尝试了几个postgre驱动程序。
这里是我的hibernate.cfg.xml:
<! - PostgreSQL - >
< property name =connection.url> jdbc:postgresql:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432 / d1vsgjgnfr1koq< /性>
< property name =connection.username> paafeblgkhhbk< / property>
< property name =connection.password>我的密码< / property>
< property name =connection.driver_class> org.postgresql.Driver< / property>
< property name =dialect> org.hibernate.dialect.PostgreSQLDialect< / property>
<! - 禁用二级缓存 - >
< property name =cache.provider_class> org.hibernate.cache.internal.NoCacheProvider< / property>
<! - 将所有执行的SQL回复到stdout - >
< property name =show_sql> true< / property>
<! - 在启动时删除并重新创建数据库模式 - >
< property name =hbm2ddl.auto>建立< / property>
获取会话时,网址,密码和用户名将被覆盖。
Configuration configuration = new Configuration();
configuration.addAnnotatedClass(Client.class);
//和其他类
尝试{
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 ======== ==================);
新的SchemaExport(配置).create(真,真);
serviceRegistry = new ServiceRegistryBuilder()。applySettings(configuration.getProperties())。buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
您可以看到驱动程序已找到。我很确定这个网址也可以(如果我尝试使用另一个链接,我会遇到连接错误)
这里是我的依赖:
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 4.1.9.Final< / version>
< /依赖关系>
< dependency>
< groupId> postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< version> 9.1-901.jdbc4< / version>
< /依赖关系>
它们按照我在本文中的说法导出(我可以看到maven在部署时正在复制它我的应用程序):
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-dependency-plugin< / artifactId>
< version> 2.4< / version>
<执行次数>
<执行>
将ID>复印依赖性< / ID>
<阶段>包< /阶段>
<目标><目标>复制依赖< /目标>< /目标>
< /执行>
< /执行次数>
< / plugin>
所以在这一点上,我看不到我做错了什么:/
以下是我得到的错误日志:
用命令
状态从开始更改为
$ b $ p
org.hibernate.annotations.common.Version
INFO:HCANN000001:Hibernate Commons Annotations {4.0.1.Final}
org.hibernate.Version logVersion
$ b 信息:HHH000412:Hibernate Core {4.1.9.Final} p>
org.hibernate.cfg.Environment
INFO:HHH000206:找不到hibernate.properties
org.hibernate.cfg.Environment buildBytecodeProvider
$ bINFO:HHH000021:字节码提供程序名称:javassist
org.hibernate.cfg.Configuration configure
信息:HHH000043:配置fr om资源:/hibernate.cfg.xml
org.hibernate.cfg.Configuration getConfigurationInputStream
信息:HHH000040 :配置资源:/hibernate.cfg.xml
org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041:配置SessionFactory:null
=== === DRIVER FOUND === ===
============================= EXPORT SCHEMA =================== =======
org.hibernate.dialect.Dialect
信息:HHH000400:使用方言:
org.hibernate.dialect.PostgreSQLDialect
org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO:HHH000227:运行就是hbm2ddl模式导出
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
上配置
INFO:HHH000402:使用Hibernate内置连接池(不适用于
生产)
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
configure
INFO:HHH000115:Hibernate连接池大小:2
$ b $ org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
configure
信息:HHH000006:自动提交模式:假
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
上配置
INFO:HHH000401:在URL
处使用驱动程序[org.postgresql.Driver] [jdbc:postgresql:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89- @ ec2-54- 243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq]
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl
配置
信息:HHH000046:连接属性:{user = paafeblgkhhbkx,
password = * *}
org.hibernate.to ol.hbm2ddl.SchemaExport execute
$ b 错误:HHH000231:架构导出不成功
java.sql.SQLException:No为
找到合适的驱动程序jdbc:postgresql:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432 / d1vsgjgnfr1koq
$ b java.sql.DriverManager.getConnection(DriverManager.java:640)上的$ b在java.sql.DriverManager.getConnection(DriverManager.java:169)上的
在
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:193)
在
org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:55)
在
在
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。
$ 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)
在com.sun.net.httpserver.Filter $ Chain.doFilter(Filter.java:83)
在sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
在com.sun.net.httpserver.Filter $ Chain.doFilter(Filter.java :86)
在
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)
在
sun.net.httpserver.ServerImpl $ DefaultExecutor.execute(ServerImpl.java:137)
在
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)
感谢您的宝贵时间!
对于您的数据库网址来说是非常可疑的:
jdbc:postgresql:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89- @ ec2-54-243-243- 252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq
细分:
- JDBC方案:
postgresql
&ndash的; OK - 主机名:
paafeblgkhhbkx
–可疑 - 端口:
PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com
–肯定是错的。
您显然尝试将用户名和密码作为连接URL的一部分,但这不是它的做法。这些都是使用单独的属性进行配置的,如果 将它们包含在URI中,这就是:
jdbc:postgresql:// localhost / test?user = fred& password = secret
作为附注,我已成功连接到您的数据库,这样除了正确的主机名外,我还可以证明您向公众公开的凭据的正确性。该更改密码了......
Sorry to bother you but I keep getting an error et I don't really understand why.
As specified in the title I'm trying to connect on my postgresql database running heroku using hibernate. My app is also running on Heroku.
It's working in local mode, I've 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 is found. I'm pretty sure the url is ok too (If I try with another one I get a connection error)
Here my depedencies :
<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 stated here in my pom (I can see maven is copying it when I deploye my app) :
<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've done wrong :/
Here is the error log I'm getting :
Starting process with command
java -cp target/classes:target/dependency/* test.Server
State changed from starting to up
org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons 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.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
=== === DRIVER FOUND === ===
============================= EXPORT SCHEMA ==========================
org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 2
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq]
org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=paafeblgkhhbkx, password=**}
org.hibernate.tool.hbm2ddl.SchemaExport execute
ERROR: HHH000231: Schema export unsuccessful
java.sql.SQLException: No suitable driver found for jdbc:postgresql://paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq
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)
at 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)
Thanks for your time !
There is something quite suspicious with your database URL:
jdbc:postgresql://paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq
Breakdown:
- JDBC scheme:
postgresql
– OK - hostname:
paafeblgkhhbkx
– suspicious - port:
PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com
– definitely wrong.
You are apparently trying to include username and password as a part of the connection URL, but that's not how it is done. These are configured using separate properties and if you are going to include them in the URI, this is how:
jdbc:postgresql://localhost/test?user=fred&password=secret
As a side note, I have successfully connected to your database so I can attest to the correctness of the credentials you have exposed to the public, in addition to the correct hostname. Time to change that password...
这篇关于没有合适的驱动程序。尝试使用Hibernate连接到Heroku上的postgresql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!