日期:2014-05-20  浏览次数:20933 次

hibernate加了驱动怎么还报错?
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
ddddddd
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at wu.hibernate.HibernateMain.main(HibernateMain.java:18)
Caused by: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 7 more




hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
  <session-factory> 
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=stuDB</property> 
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property> 
<property name="hibernate.connection.username">sa</property> 
<property name="hibernate.connection.password">123456</property> 
<property name="show_sql">ture</property> 
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> 
<property name="hibernate.jdbc.batch_size">16</property> 
<mapping resource="wu/hibernate/Student.hbm.xml"/> 
  </session-factory> 
</hibernate-configuration> 




------解决方案--------------------

希望你能够认真看别人给你的回复,你本来不就是求助的么?

第一,你没有说清楚你的URL地址是否按照我说的改成jdbc:sqlserver://localhost:1433;DatabaseName=stuDB

第二,你没有说清楚我一直想问的你是怎么运行程序的,是eclipse里面调试还是直接部署了程序

第三,你也没有说清楚你怎么加的Jar包

1.改URL地址
2.工程-右键-build path-configuration-add jars或者add external jars 然后选择你对应的jdbc驱动包

如果还不成功,加我QQ 519582737,我看看你驱动包是不是能用的

探讨
引用:
你的jar包不匹配啊,到官网下载一个jar包copy到你的lib文件夹下面就可以了

我就是在官方下的sqljdbc4.jar