2014-02-13 84 views
1

我嘗試使用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中。

+0

它是一個web應用? – Naren

+0

不,直到現在它只是一個類的主要方法 – chuhx

+1

檢查hibernate.cfg.xml文件...參數..有些事情可能是錯誤的 – Naren

回答

0

這是您的配置文件的問題。

檢查你希德在

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> 
相關問題