hibernate microsoft sql server crud

时间:2013-04-09 14:44:27

标签: sql-server-2008 hibernate crud

尝试连接初始Microsoft SQL Server hibernate会话类但出现以下错误:

创建初始SessionFactory

failed.org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.microsoft.sqlserver.jdbc.SQLServerDriver class not found
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.vaneck.rsutedja.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
    at com.vaneck.rsutedja.dao.hibernate.Test.main(Test.java:19)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.microsoft.sqlserver.jdbc.SQLServerDriver class not found
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:107)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2275)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2271)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1780)
    at com.vaneck.rsutedja.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
    ... 1 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:146)
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:104)
    ... 15 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:293)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:143)
    ... 16 more

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您应该将SQL Server的Microsoft JDBC驱动程序添加到类路径中。参见:

http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx