jdbc.java

来自「JSP科技企业信息管理系统,可以做为学习JSP的好资料」· Java 代码 · 共 86 行

JAVA
86
字号
// FrontEnd Plus GUI for JAD
// DeCompiled : jdbc.class

package jdbc;

import java.sql.*;
import java.util.Enumeration;
import java.util.Vector;

public class jdbc
{

    private int inuse;
    private int max;
    private Vector connections;

    public jdbc()
    {
        inuse = 0;
        max = 9999;
        connections = new Vector();
    }

    public synchronized void releaseConnection(Connection connection)
    {
        connections.addElement(connection);
        inuse--;
    }

    public synchronized Connection getConnection()
    {
        Connection connection = null;
        if(connections.size() > 0)
        {
            connection = (Connection)connections.elementAt(0);
            connections.removeElementAt(0);
            try
            {
                if(connection.isClosed())
                    connection = getConnection();
            }
            catch(SQLException sqlexception) { }
        } else
        if(max == 0 || inuse < max)
            connection = newConnection();
        if(connection != null)
            inuse++;
        return connection;
    }

    private Connection newConnection()
    {
        Connection connection = null;
        try
        {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        }
        catch(Exception exception) { }
        try
        {
            connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tech", "tech", "wushili");
        }
        catch(SQLException sqlexception)
        {
            sqlexception.printStackTrace();
            return null;
        }
        return connection;
    }

    public synchronized void closeCon()
    {
        for(Enumeration enumeration = connections.elements(); enumeration.hasMoreElements();)
        {
            Connection connection = (Connection)enumeration.nextElement();
            try
            {
                connection.close();
            }
            catch(SQLException sqlexception) { }
        }

        connections.removeAllElements();
    }
}

⌨️ 快捷键说明

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