[学习笔记]
6.Oracle DataSource and SingleTon:
import oracle.jdbc.pool.OracleDataSource;
import java.sql.Connection;
import java.sql.*;
public class OracleSingletonDataSource {
static private OracleDataSource ods;
private OracleSingletonDataSource() {
try{
ods = new OracleDataSource();
ods.setURL(“jdbc:oracle:thin:@localhost:1521:qixy”);
ods.setUser(“scott”);
ods.setPassword(“tiger”);
}catch(Exception e){
e.printStackTrace();
}
}
public static Connection getConnection() throws Exception {
if (ods==null)
{
new OracleSingletonDataSource();
// ods.getConnection();
}
Connection con =null;
try {
con = ods.getConnection();
} catch (SQLException ex) {
ex.printStackTrace();
}
return con;
}
}
文章转载自原文: https://blog.csdn.net/qq_43650923/article/details/100654724