一、数据库连接工具类
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionUtils {
private final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
private final String URL = "jdbc:oracle:thin:@###.###.###.###:1521:****";
private final String USERNAME = "username";
private final String PASSWORD = "password";
private ConnectionUtils(){}
private static class DataBaseHolder{
private static final ConnectionUtils instance = new ConnectionUtils();
}
public static ConnectionUtils getInstance(){
return DataBaseHolder.instance;
}
public Connection getConnectionion() {
Connection conn = null;
try {
Class.forName(ORACLE_DRIVER);
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
二、处理ResultSet结果集的公共接口
import java.sql.ResultSet;
public interface ResultSetHandler<T> {
public T handle(ResultSet rs);
}
三、SimpleJdbcTemplate主工具类
import java.sql.Connection;
import java.sql.PreparedStatement;