运行一个测试类出现如下
- Java code
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).log4j:WARN Please initialize the log4j system properly.Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.sqlserver.jdbc.SQLServerDriver at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:89) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79) at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:425) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339) at test.test.main(test.java:31)Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:84) ... 8 more
------解决方案--------------------
添加SqlServer的jar驱动包到你的build path下面去。
要是web project的话,那就把那个jar包复制到WEB-INF的lib目录下,会自动给你设置好build path的。
很明显是找不到SqlServer的驱动类Driver嘛。
------解决方案--------------------
就是jar包得问题,这个自己应该可以看明白的啊。
------解决方案--------------------
错误提示上说的是jdbc驱动错误,你用的是哪个数据库,sql2005的是不同于其他数据库的,必须用jtds包驱动,还有就是你把数据库连接代码也贴出来吧!
------解决方案--------------------