javax.servlet.ServletException: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z

javax.servlet.ServletException: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z

2013-06-26 05:53:30|  分类: JAVA开发|字号 订阅

 
 
copy from :http://www.cnblogs.com/Snowfun/archive/2010/12/17/1909197.html

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" java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z 
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123) 
 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 dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31) 
 at dao.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13) 
 at HibernateDAOTest.main(HibernateDAOTest.java:16)

解决:microsoft提供的数据库驱动存在bug。需要换一种驱动连接,使用jtds(下载地址:http://sourceforge.net/projects/jtds/files/)下载jtds1.2版,解压得到jtds-1.2.jar,引用到eclipse中项目目录下(去除原驱动引用),更改hibernate配置文件:

原驱动连接配置:

<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
        <property name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>
更改jtds连接:   
        <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
        <property name="connection.url">jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>

问题得到解决。补充:java代码调原驱动连接数据库是没有问题的,搭配hibernate会有此问题。

在连接mysql5.1时正常,连接sql2000时就是连不上,郁闷,终于在网上找到了解答,原来是sql驱动和hibernate的兼容 性问题,现问题已解决,留此文备查.

上一篇:Java常用类库 读书笔记 二


下一篇:apache开启.htaccess