dbpool.java

来自「天乙代码src_531.rar 天乙代码src_531.rar 天乙代」· Java 代码 · 共 47 行

JAVA
47 行
字号
package com.laoer.bbscs.db;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;

/**
 * <p>Title: 天乙社区V5.0</p>
 * <p>Description: BBS-CS天乙社区V5.0</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: laoer.com</p>
 * @author 龚天乙
 * @version 5.0
 */

public class DBPool {

  public Connection con;

  public DBPool() {
  }

  public DBPool(String jndi) throws Exception {
    Context env = null;
    DataSource source = null;
    try {
      env = (Context)new InitialContext().lookup("java:comp/env");
      source = (DataSource) env.lookup(jndi);
      this.con = source.getConnection();

    }
    catch (Exception e) {
      throw e;
    }
  }

  public Connection getCon() {
    if (this.con != null) {
      return this.con;
    }
    else {
      return null;
    }
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?