一。JDBC连接类
package com.xwt.dao.impl;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.xwt.dao.DriverDao;
public class DriverDaoSupport implements DriverDao {
public final static ResourceBundle bundle = ResourceBundle.getBundle("DBConnectionConfig");// DBConnectionConfig.properties配置文件的名称
public final static String DRIVER = bundle.getString("mysql.database.driver");
public final static String URL = bundle.getString("mysql.database.url");
public final static String DBNAME = bundle.getString("mysql.database.user");
public final static String DBPASS = bundle.getString("mysql.database.password");
public Connection getConnection() {
Connection conn = null;
try {
Class.forName(DRIVER);
conn = (Connection) DriverManager
.getConnection(URL, DBNAME, DBPASS);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
二。Spring连接
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
classpath:DBConnectionConfig.properties
三。DBConnectionConfig.properties配置文件
#mysql
mysql.database.driver=com.mysql.jdbc.Driver
mysql.database.url=jdbc\:mysql\://127.0.0.1\:3306/51didi?useUnicode\=true&characterEncoding\=utf-8
mysql.database.user=root
mysql.database.password=123456
mysql.database.maxActive=100
mysql.database.maxIdle=30
mysql.database.maxWait=500
#oracle
oracle.database.driver=oracle.jdbc.driver.OracleDriver
oracle.database.url=jdbc\:oracle\:thin\:@localhost\:1521\:51didi
oracle.database.user=root
oracle.database.password=123456