java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子

[学习笔记]

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

 

    原文作者:海中一神兽
    原文地址: https://www.cnblogs.com/haima1949/p/11619777.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞