简体   繁体   English

没有合适的司机。尝试使用Hibernate连接到Heroku上的postgresql数据库

[英]No suitable driver. Trying to connect to a postgresql database on Heroku using Hibernate

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. 正如标题中所指定的,我正在尝试使用hibernate在运行heroku的postgresql数据库上进行连接。 My app is also running on Heroku. 我的应用程序也在Heroku上运行。

It's working in local mode, I've tried several postgre drivers. 它在本地模式下工作,我尝试了几个postgre驱动程序。

Here's my hibernate.cfg.xml : 这是我的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) : 它们按照我的pom中的说明导出(我可以看到maven在部署我的应用程序时正在复制它):

<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 使用命令java -cp target/classes:target/dependency/* test.Server启动进程java -cp target/classes:target/dependency/* test.Server

State changed from starting to up 国家从开始变为上升

org.hibernate.annotations.common.Version org.hibernate.annotations.common.Version

INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} 信息:HCANN000001:Hibernate Commons Annotations {4.0.1.Final}

org.hibernate.Version logVersion org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.1.9.Final} 信息:HHH000412:Hibernate Core {4.1.9.Final}

org.hibernate.cfg.Environment org.hibernate.cfg.Environment中

INFO: HHH000206: hibernate.properties not found 信息:HHH000206:找不到hibernate.properties

org.hibernate.cfg.Environment buildBytecodeProvider org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist 信息:HHH000021:字节码提供程序名称:javassist

org.hibernate.cfg.Configuration configure org.hibernate.cfg.Configuration配置

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 信息:HHH000043:从资源配置:/hibernate.cfg.xml

org.hibernate.cfg.Configuration getConfigurationInputStream org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 信息:HHH000040:配置资源:/hibernate.cfg.xml

org.hibernate.cfg.Configuration doConfigure org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null 信息:HHH000041:已配置的SessionFactory:null

=== === DRIVER FOUND === === === ===找到了驾驶员=== ===

============================= EXPORT SCHEMA ========================== =============================出口计划=================== =======

org.hibernate.dialect.Dialect 的org.hibernate.dialect.Dialect

INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect 信息:HHH000400:使用方言:org.hibernate.dialect.PostgreSQLDialect

org.hibernate.tool.hbm2ddl.SchemaExport execute org.hibernate.tool.hbm2ddl.SchemaExport执行

INFO: HHH000227: Running hbm2ddl schema export 信息:HHH000227:运行hbm2ddl架构导出

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

INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) 信息:HHH000402:使用Hibernate内置连接池(不供生产使用!)

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

INFO: HHH000115: Hibernate connection pool size: 2 信息:HHH000115:Hibernate连接池大小:2

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

INFO: HHH000006: Autocommit mode: false 信息:HHH000006:自动提交模式:false

org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 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] 信息: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 configure org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000046: Connection properties: {user=paafeblgkhhbkx, password= * *} 信息:HHH000046:连接属性:{user = paafeblgkhhbkx,password = * *}

org.hibernate.tool.hbm2ddl.SchemaExport execute org.hibernate.tool.hbm2ddl.SchemaExport执行

ERROR: HHH000231: Schema export unsuccessful 错误:HHH000231:架构导出失败

java.sql.SQLException: No suitable driver found for jdbc:postgresql://paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432/d1vsgjgnfr1koq java.sql.SQLException:没有为jdbc找到合适的驱动程序:postgresql:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432 / d1vsgjgnfr1koq

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

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

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

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

at org.hibernate.tool.hbm2ddl.DatabaseExporter.(DatabaseExporter.java:52) 在org.hibernate.tool.hbm2ddl.DatabaseExporter。(DatabaseExporter.java:52)

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

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

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

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

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

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

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

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

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

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

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

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

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

at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:83) 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 $ Exchange.run(ServerImpl.java:561)

at sun.net.httpserver.ServerImpl$DefaultExecutor.execute(ServerImpl.java:137) 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.handle(ServerImpl.java:367)

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

at java.lang.Thread.run(Thread.java:679) 在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 JDBC:在PostgreSQL:// paafeblgkhhbkx:PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com:5432 / d1vsgjgnfr1koq

Breakdown: 分解:

  • JDBC scheme: postgresql – OK JDBC方案: postgresql - 好的
  • hostname: paafeblgkhhbkx – suspicious 主机名: paafeblgkhhbkx - 可疑
  • port: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com – definitely wrong. 端口: PhZEtHl2RHwbWDQJJOurmej89-@ec2-54-243-243-252.compute-1.amazonaws.com - 绝对错误。

You are apparently trying to include username and password as a part of the connection URL, but that's not how it is done. 您显然试图将用户名和密码作为连接URL的一部分包含在内,但这不是它的完成方式。 These are configured using separate properties and if you are going to include them in the URI, this is how: 这些是使用单独的属性进行配置,如果要包括他们在URI,这是怎么了:

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... 是时候更改密码了......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用JDBC连接Heroku数据库时找不到合适的驱动程序 - No suitable driver found on attempt to connect Heroku Database using JDBC 我无法将App连接到我的PostgreSQL数据库-没有合适的驱动程序 - I cannot connect App to my PostgreSQL database - No Suitable Driver 尝试连接到SQLite数据库,但始终找不到合适的驱动程序 - Trying to connect to a SQLite database, keep getting no Suitable Driver Found 无法连接到数据库(找不到合适的驱动程序) - Unable to connect to database (No suitable driver found) 在连接到Amazon MySQL数据库时找不到合适的驱动程序 - No suitable driver found on connect to Amazon MySQL Database 获取org.hibernate.HibernateException:未配置CurrentSessionContext! 尝试连接到heroku-postgresql Hibernate时 - getting org.hibernate.HibernateException: No CurrentSessionContext configured! when trying to connect to heroku-postgresql Hibernate 'java.sql.SQLException: 没有合适的驱动程序' [SQLException, Heroku, Postgresql] - 'java.sql.SQLException: No suitable driver fround' [SQLException, Heroku, Postgresql] Jython-尝试连接到java.sq l.SQLException中的数据库结果:找不到合适的驱动程序 - Jython - Trying to connect to database results in java.sq l.SQLException: No suitable driver found 尝试连接到我的sql数据库时出现异常,提示“找不到合适的驱动程序” - Trying to connect to my sql database getting exception saying “no suitable driver found” 尝试使用Eclipse和Hibernate 5连接到mysql数据库 - trying to connect to mysql database using eclipse and hibernate 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM