⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdcconnection.java

📁 利用Java写的数据库连接池代码
💻 JAVA
字号:
package bean;


import java.sql.*;
import java.util.*;
import java.io.*;

/**
 * <p>Title: CSMIS</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author YIDONG(一冬)
 * @version 1.0
 */

import java.sql.*;
import java.util.*;
import java.io.*;

public class JDCConnection implements Connection{

    private Connection conn;
    private boolean inuse;
    private long timestamp;


    public JDCConnection(Connection conn) {
      DBConnectionManager.getInstance().addConnect();
        this.conn=conn;
        this.timestamp=System.currentTimeMillis();
    }


        public long getUseTime() {
        return System.currentTimeMillis()-timestamp;
    }

        public long getinitTime() {
        return timestamp;
    }


    public void close() throws SQLException {
      DBConnectionManager.getInstance().removeConnect();
//        pool.returnConnection(this);
                        conn.close();
    }


    protected Connection getConnection() {
        return conn;
    }

        public void setAutoCommit(boolean autoCommit) throws SQLException {
        conn.setAutoCommit(autoCommit);
    }

    public boolean getAutoCommit() throws SQLException {
        return conn.getAutoCommit();
    }

    public void commit() throws SQLException {
        conn.commit();
    }

    public void rollback() throws SQLException {
        conn.rollback();
    }

    public boolean isClosed() throws SQLException {
        return conn.isClosed();
    }

        public SQLWarning getWarnings() throws SQLException {
        return conn.getWarnings();
    }

    public void clearWarnings() throws SQLException {
        conn.clearWarnings();
    }


        public boolean validate() {
        try {
            conn.getMetaData();
        }catch (Exception e) {
            return false;
        }
        return true;
    }


    public PreparedStatement prepareStatement(String sql) throws SQLException {
        return conn.prepareStatement(sql);
    }

    public CallableStatement prepareCall(String sql) throws SQLException {
        return conn.prepareCall(sql);
    }

    public Statement createStatement() throws SQLException {
        return conn.createStatement();
    }

    public String nativeSQL(String sql) throws SQLException {
        return conn.nativeSQL(sql);
    }

    public DatabaseMetaData getMetaData() throws SQLException {
        return conn.getMetaData();
    }

    public void setReadOnly(boolean readOnly) throws SQLException {
        conn.setReadOnly(readOnly);
    }

    public boolean isReadOnly() throws SQLException {
        return conn.isReadOnly();
    }

    public void setCatalog(String catalog) throws SQLException {
        conn.setCatalog(catalog);
    }

    public String getCatalog() throws SQLException {
        return conn.getCatalog();
    }

    public void setTransactionIsolation(int level) throws SQLException {
        conn.setTransactionIsolation(level);
    }

    public int getTransactionIsolation() throws SQLException {
        return conn.getTransactionIsolation();
    }

        public CallableStatement prepareCall(String a, int b, int c) throws SQLException {
        return conn.prepareCall(a,b,c);
    }

        public Map getTypeMap() throws SQLException {
        return conn.getTypeMap();
    }

        public void setTypeMap(Map m) throws SQLException {
         conn.setTypeMap(m);
    }

        public Statement createStatement(int a,int b) throws SQLException {
         return conn.createStatement(a,b);
    }

        public PreparedStatement prepareStatement(String a, int b, int c) throws SQLException {
        return conn.prepareStatement(a,b,c);
    }

    //////1.4

    public PreparedStatement prepareStatement(String sql, String columnNames[])
       throws SQLException
   {
     return conn.prepareStatement(sql,columnNames);
   }

   public Savepoint setSavepoint(String name) throws SQLException
   {
     return	conn.setSavepoint(name);
   }

   public PreparedStatement prepareStatement(String sql, int columnIndexes[])
       throws SQLException
   {
     return conn.prepareStatement(sql, columnIndexes);
   }

   public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
       throws SQLException
   {
     return conn.prepareStatement(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
   }

   public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
       throws SQLException
   {
     return conn.prepareStatement(sql, autoGeneratedKeys);
   }

   public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
       throws SQLException
   {
     return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
   }

   public Statement createStatement(int resultSetType, int resultSetConcurrency,int resultSetHoldability)
       throws SQLException
   {
     return conn.createStatement(resultSetType, resultSetConcurrency,resultSetHoldability);
   }

   public void setHoldability(int holdability) throws SQLException
   {
     conn.setHoldability(holdability);
   }
   public int getHoldability() throws SQLException
   {
     return conn.getHoldability();
   }

   public Savepoint setSavepoint() throws SQLException
   {
     return conn.setSavepoint();
   }

   public void rollback(Savepoint savepoint) throws SQLException
   {
     conn.rollback(savepoint);
   }

   public void releaseSavepoint(Savepoint savepoint) throws SQLException
   {
     conn.releaseSavepoint(savepoint);
   }



}

⌨️ 快捷键说明

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