原理就不说了 百度一坨坨
配置文件:
driverClassName=dm.jdbc.driver.DmDriver
url=jdbc\:dm\://192.168.0.1\:5240?autoReconnect\=true
username=aaaa
password=qqqqqq
#最小空闲连接
minIdle=5
#最大空闲连接
mzxIdle=20
maxActive=400
#初始化连接数
initialSize=30
#连接遗漏时是否打印
logAbandoned=true
#是否自动回收超时连接
removeAbandoned=true
#等待超时最大时间
maxWait=5000
编写测试代码
package createTmrData;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;
public class JDBCTest {
public static void main(String[] args) {
BasicDataSource bs = null;
Properties p = new Properties();
InputStream inStream = JDBCTest.class.getResourceAsStream("/conf/jdbc.properties");
try {
p.load(inStream);
bs = BasicDataSourceFactory.createDataSource(p);
Connection conn = bs.getConnection();
Statement stm = conn.createStatement();
ResultSet set = stm.executeQuery("select count(*) from RDP_MD_CUSTOMERT