spring mybatis連線access資料庫

2022-03-29 16:43:11 字數 2563 閱讀 5696

1.所需jar包:

spring

mybatis

common-dhcp (版本1.4以上,1.4以下無法支援connectionproperties屬性)

注意事項:

連線access資料庫前請關閉log4j, log4j的控制台sql日誌輸出會導致 not data sqlexception

2.pom.xml

<

dependency

>

<

groupid

>org.springframework

groupid

>

<

artifactid

>spring-core

artifactid

>

<

version

>3.1.1.release

version

>

dependency

>

<

dependency

>

<

groupid

>org.springframework

groupid

>

<

artifactid

>spring-context

artifactid

>

<

version

>3.1.1.release

version

>

dependency

>

<

dependency

>

<

groupid

>org.springframework

groupid

>

<

artifactid

>spring-jdbc

artifactid

>

<

version

>3.1.1.release

version

>

dependency

>

<

dependency

>

<

groupid

>org.springframework

groupid

>

<

artifactid

>spring-webmvc

artifactid

>

<

version

>3.1.1.release

version

>

dependency

>

<

dependency

>

<

groupid

>org.mybatis

groupid

>

<

artifactid

>mybatis-spring

artifactid

>

<

version

>1.2.0

version

>

dependency

>

<

dependency

>

<

groupid

>org.mybatis

groupid

>

<

artifactid

>mybatis

artifactid

>

<

version

>3.2.2

version

>

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=;dbq=d:/workspace/eclipse/attend/data/attend.mdb"

/>

<

property

name

="connectionproperties"

>

<

value

>charset=gbk

value

>

property

>

bean

>

connectionproperties屬性重要,不加上會導致中文亂碼

spring mybatis讀寫分離

一 配置定義資料庫連線屬性 二 定義bean 三 事務定義 四 配置外掛程式 五 編寫動態資料來源類 public class dynamicdatasource extends abstractroutingdatasource setdefaulttargetdatasource writeda...

spring mybatis事務不回滾

對spring,mybatis進行整合時發現事務不能進行回滾處理,上網查了很多資料依舊還沒解釋,很多都是說要丟擲乙個runtimeexception才能回滾的,但嘗試過多種還不能,如下 classpath jdbc.properties bolgservice bolgflowservice 檢視資...

Spring Mybatis 增刪改查

select from student where id insert into student name,code values delete from student where code update student set name where code select id,name,cod...