spring+mybatis连接access数据库

1.所需jar包:

spring

mybatis

common-dhcp (版本1.4以上,1.4以下无法支持connectionProperties属性)

 

注意事项:

连接access数据库前请关闭log4j, log4j的控制台sql日志输出会导致 not data SQLException

 

2.pom.xml

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-coreartifactId>
      <version>3.1.1.RELEASEversion>
    dependency>
    
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-contextartifactId>
      <version>3.1.1.RELEASEversion>
    dependency>
    
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-jdbcartifactId>
      <version>3.1.1.RELEASEversion>
    dependency>
    
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>3.1.1.RELEASEversion>
    dependency>
    
    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatis-springartifactId>
      <version>1.2.0version>
    dependency>
    
    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatisartifactId>
      <version>3.2.2version>
    dependency>      

3.spring-context.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
        <property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver" />  
        <property name="url" value="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:/workspace/eclipse/attend/data/attend.mdb" />
        <property name="connectionProperties">  
            <value>charSet=gbkvalue>
        property>  
bean>
connectionProperties属性重要,不加上会导致中文乱码

转载于:https://www.cnblogs.com/sz-zzm/p/5244757.html

你可能感兴趣的:(spring+mybatis连接access数据库)