本文向大家介绍Hibernate Access的支持的常用方法,看完本文你肯定有不少收获,希望本文能教会你更多东西

1、Hibernate  Access的支持

方法一:

下载两个jar包,一个是Access的JDBC驱动包;另一个是数据库方言包,里面有支持Access方言的类。

下载地址:http://www.hxtt.com/access.zip,http://www.hxtt.com/test/hibernate.zip。

配置如下:

xml 代码

<property name="hibernate.dialect">   


     com.hxtt.support.hibernate.HxttAccessDialect   



property>     




<property name="hibernate.connection.url">   



     jdbc:access:///f:/mdbfiles/aaa.mdb   



property>     




<property name="hibernate.connection.driver_class">   



     com.hxtt.sql.access.AccessDriver   



property>   

方法二:

首先先要在ODBC里配置好我们的Access数据库,控制面板--->管理工具--->ODBC,选择系统DSN选项卡,按添加按钮,选Driver   do   Mircosoft   Access(*.mdb),完成,在DataSource   Name中输入你想要的名字比如hibtest,后面将用它来查找数据库。然后指定数据库所在位置就OK了。   

Hibernate描述文件可以是一个properties或xml   文件,其中最重要的是定义数据库的连接。我这里列出的是一个XML格式的hibernate.cfg.xml描述文件。   
xml 代码

xml version="1.0" encoding="utf-8"?>         



   PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"         



   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">         





<hibernate-configuration>         




     <session-factory name="java:/hibernate/HibernateFactory">         




          <property name="show_sql">trueproperty>         




          <property name="connection.driver_class">         




               sun.jdbc.odbc.JdbcOdbcDriver   




          property>         




          <property name="connection.url">         




               jdbc:odbc:hibtest    




          property>         




          <property name="connection.username">saproperty>         




          <property name="connection.password">property>         




          <property name="dialect">         




               net.sf.hibernate.dialect.MySQLDialect    




          property>         




          <mapping resource="Customer.hbm.xml"/>          




     session-factory>          




  hibernate-configuration>