Hibernate,JDBC:错误调用驱动程序#连接
问题描述:
我尝试使用Hibernate连接到我的数据库。但是,当我建立我的SessionFactory,它总是抛出一个JDBCCOnnectionException:错误调用驱动程序#连接Hibernate,JDBC:错误调用驱动程序#连接
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:118)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at HibernateTest.main(HibernateTest.java:19)
代码:
Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder();
sb.applySettings(cfg.getProperties());
StandardServiceRegistry standardServiceRegistry = sb.build();
SessionFactory sessionFactory = cfg.buildSessionFactory(standardServiceRegistry); //<-- Exception here
System.err.println("configuration done");
hibernate.cfg.xml文件加载完成并成功。 我还添加了mysql-connector-java-5.1.29.bin.jar到我的buildpath中。
答
这是您的配置文件的问题。
检查你希德在
hibernate.cfg.xml file
对于Oracle Express版本:
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
对于Oracle企业版:
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
它是一个web应用? – Naren
不,直到现在它只是一个类的主要方法 – chuhx
检查hibernate.cfg.xml文件...参数..有些事情可能是错误的 – Naren