标签:
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={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:/workspace/eclipse/attend/data/attend.mdb" /> <property name="connectionProperties"> <value>charSet=gbk</value> </property> </bean>
connectionProperties属性重要,不加上会导致中文乱码
标签:
原文地址:http://www.cnblogs.com/sz-zzm/p/5244757.html