hibernate连接Access数据库方法一:用Access_jdbc30.jar包 (此包在使用hibernate中会出现查询记录只能查询1000条,需要下载正版的jar包)
第一种方法:
第一步导入Access包,在配置文件中配置下面信息
<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项目会报错
第一种方法:
第一步导入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项目会报错