Hibernate连接Access数据库

hibernate连接Access数据库方法一:用Access_jdbc30.jar包 (此包在使用hibernate中会出现查询记录只能查询1000条,需要下载正版的jar包)

第一种方法:
第一步导入Access包,在配置文件中配置下面信息
<?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">  
  
<!-- Generated by MyEclipse Hibernate Tools.                   -->  
<hibernate-configuration>  
  
<session-factory>  
    <property name="connection.url">  
        jdbc:access:///G:/ACCESS/test1.mdb   
    </property>  
    <property name="myeclipse.connection.profile">access</property>  
    <property name="connection.driver_class">  
        com.hxtt.sql.access.AccessDriver   
    </property>  
    <property name="show_sql">true</property>  
    <property name="connection.username"></property>  
    <property name="connection.password"></property>  
    <property name="hibernate.dialect">  
        com.hxtt.support.hibernate.HxttAccessDialect   
    </property>
    <property name="dialect">com.hxtt.support.hibernate.HxttAccessDialect</property>  
    <mapping resource="com/jsw/hibernate/entity/TUser.hbm.xml" />  
  
</session-factory>  
  
</hibernate-configuration>
上面的配置是错误的,
 <property name="hibernate.dialect">  
        com.hxtt.support.hibernate.HxttAccessDialect  
      应改为:org.hibernate.dialect.SQLServerDialect否侧会抛出org/hibernate/type/StandardBasicTypes异常
 </property>


正确的配置如下
<?xml version='1.0' encoding='GBK'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>


<session-factory>
<property name="connection.url">
jdbc:access:///d:/EasychannelAccess/easychannel.accdb
</property>
<property name="connection.driver_class">
com.hxtt.sql.access.AccessDriver
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="show_sql">true</property>
<mapping resource="po/User.hbm.xml" />


</session-factory>


</hibernate-configuration>




第二种方法:
用java自带的jdbc驱动,使用sqlserver方言,不过会出现一些小问题模糊查询方面和sql server数据库略有不同


<?xml version='1.0' encoding='GBK'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>


<session-factory>
<property name="dialect">
org.hibernate.dialect.SQLServer7Dialect
</property>
<property name="connection.url">
jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};
DBQ=D://EasychannelAccess//easychannel.accdb
</property>
<property name="connection.driver_class">
sun.jdbc.odbc.JdbcOdbcDriver
</property>
<property name="show_sql">true</property>
<mapping resource="po/User.hbm.xml" />


</session-factory>


</hibernate-configuration>


用hibernate3框架的话,使用jdbc连接org.hibernate.dialect.SQLServerDialect 而不是
 org.hibernate.dialect.SQLServer7Dialect 不然运行web项目会报错
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值