简单测试类
----------------------------------------------------------------------------------------------------------------------------------------------
package com.allcam.test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class ConnectAccess { /** * 初学者请注意: * 1:先建立一个access文件a1.mdb,并放在D:/下; * 2:在数据库文件a1.mdb中建立一个表Table1; * 3:为Table1添加一列,并插入至少一条记录; * 4:本文是一个完整的类,直接拿去运行就可以。 */ public static void main(String args[]) throws Exception { ConnectAccess ca = new ConnectAccess(); ca.ConnectAccessFile(); //ca.ConnectAccessDataSource(); } public void ConnectAccessFile() throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); /** * 直接连接access文件。 */ String dbur1 = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F://AccessControl//iCCard3000.mdb;charSet=UTF-8"; Connection conn = DriverManager.getConnection(dbur1, "sa", "168168"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from t_d_SwipeRecord"); while (rs.next()) { System.out.println(rs.getString(1)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); System.out.println(rs.getString(4)); } rs.close(); stmt.close(); conn.close(); }}
---------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
mybatis
----------------------------------------------------------------------------------------------------------------------------------------------
########zhmu cfg begin####### zhmu.dbtype=mysql zhmu.db.driverClassName=sun.jdbc.odbc.JdbcOdbcDriver zhmu.db.url=jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F://AccessControl//iCCard3000.mdb;charSet=UTF-8 zhmu.db.username=sa zhmu.db.password=168168 zhmu.db.testsql=select 1
<bean id="zhmuDataSource" class="org.apache.commons.dbcp2.BasicDataSource"
init-method="init" destroy-method="close"> <property name="driverClassName" value="${zhmu.db.driverClassName}"/> <!-- 基本属性 url、user、password --> <property name="url" value="${zhmu.db.url}"/> <property name="username" value="${zhmu.db.username}"/> <property name="password" value="${zhmu.db.password}"/> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="${zhmu.database.connection.idle}"/> <property name="minIdle" value="${zhmu.database.connection.min}"/> <!-- 配置获取连接等待超时的时间 --> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000"/> <property name="validationQuery" value="${zhmu.db.testsql}"/> <property name="testWhileIdle" value="true"/> <property name="testOnBorrow" value="false"/> <property name="testOnReturn" value="false"/> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="true"/> <!-- 配置监控统计拦截的filters --> <!-- <property name="filters" value="stat" /> --> </bean>