给出一个Oracle DataSource 数据源单态模式的例子?

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) {

详情请见:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner10_web.html#OracleDataSourceandSingleTon

猜你喜欢

转载自www.cnblogs.com/mark-to-win/p/9708715.html