已经发过去了,记得收啊里面有三个文件,分别是:
.jar文件是连接池的,包里面也有源文件.properties是它的配置文件.jsp是一个连接数据库的例子

解决方案 »

  1.   

    http://www.csdn.net/develop/article/19/19189.shtm
      

  2.   

    ================   DBConnectionManager.java    ==================
    package dbutil;import java.io.*;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.Properties;
    import java.util.Vector;/**
     * 数据库连接池
     */
    public class DBConnectionManager implements Serializable
    {
    /**
     * 连接池的实例
     */
       static private DBConnectionManager instance; /**
     * 正在被使用数据库连接个数
     */
    private int checkedOut; /**
     * 保存空闲数据库连接的向量
     */
    private Vector freeConnections; /**
     * 允许取得的最大的连接个数
     */
    private int max; /**
     * 数据库密码
     */
    private String password; /**
     * 数据库主机地址
     */
    private String url; /**
     * 数据库用户名
     */
    private String user;
    /**
     * 供外部调用的取得数据库连接的方法
     * @param 可用的数据库连接
     */
    public static synchronized Connection getConnection()
    {
    if (instance == null)
    {
    instance = new DBConnectionManager();
    instance.init();
    }
    return instance.getConn();
    } /**
     *读取配置文件内容
     */
    private void init()
    {
    InputStream is = getClass().getResourceAsStream("./db.conf");
    Properties dbProps = new Properties();
    String filename = null;
    freeConnections = new Vector();
    try
    {
    dbProps.load(is);
    }catch (Exception e)
    {
    System.err.println("Can not read config file!");
    return;
    }
    url = dbProps.getProperty("url");
    user = dbProps.getProperty("user","root");
    password = dbProps.getProperty("password");
    String maxConn = dbProps.getProperty("maxconn","50");
    try
    {
    max = Integer.parseInt(maxConn);
    }catch(Exception e){}
    String driverClass = dbProps.getProperty("driver");
    try
    {
    Object obj = Class.forName(driverClass).newInstance();
    DriverManager.registerDriver((Driver)obj);
    }catch(Exception e)
    {
    System.out.println("Can not load driver:"+driverClass);
    }
    } /**
     * 取得一个空闲连接或者新建一个连接
     */
    private Connection getConn()
    {
    Connection con = null;
    if(freeConnections.size() > 0)
    {
    con = (Connection) freeConnections.firstElement();
    freeConnections.removeElementAt(0);
    try
    {
    if (con.isClosed())
    {
    con = newConn();
    }
    }catch (SQLException e)
    {
    return null;
    }
    }else
    {
    if (checkedOut >= max)
    {
    return null;
    }
    con = newConn();
    }
    if (con != null)
    {
    checkedOut++;
    }
    return con;
    } /**
     * 建立一个新的数据库连接
     */
    private Connection newConn()
    {
    Connection con = null;
    try
    {
    if (user == null)
    {
    con = DriverManager.getConnection(url);
    }else
    {
    con = DriverManager.getConnection(url, user, password);
    }
    }catch (SQLException e)
    {
    e.printStackTrace();
    return null;
    }
    return con;
    } /**
     * 释放连接
     */
    public static synchronized void freeConnection(Connection con)
    {
    if (instance == null)
    {
    instance = new DBConnectionManager();
    instance.init();
    }
    instance.freeConn(con);
    } /**
     * ConnectionManager实例释放连接
     */
    private void freeConn(Connection con)
    {
    freeConnections.addElement(con);
    checkedOut--;
    } /**
     * 释放所有连接
     */
    /*
    public synchronized void release()
    {
    Enumeration allConnections = freeConnections.elements();
    while (allConnections.hasMoreElements())
    {
    Connection con = (Connection) allConnections.nextElement();
    try
    {
    con.close();
    }catch (SQLException e)
    {
    e.printStackTrace();
    }
    }
    freeConnections = new Vector();
    checkedOut = 0;
    }*/
    }
    ///:~
    ==================   db.properties  ==========================url=jdbc:mysql://150.0.1.111/beijing?useUnicode=true&charsetEncoding=ISO-8859-1
    driver=org.gjt.mm.mysql.Driver
    user=easyweb
    password=
    maxconn=60
    output=false
      

  3.   

    package dbutil;import java.io.*;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.Properties;
    import java.util.Vector;/**
     * 数据库连接池
     */
    public class DBConnectionManager implements Serializable
    {
    /**
     * 连接池的实例
     */
       static private DBConnectionManager instance; /**
     * 正在被使用数据库连接个数
     */
    private int checkedOut; /**
     * 保存空闲数据库连接的向量
     */
    private Vector freeConnections; /**
     * 允许取得的最大的连接个数
     */
    private int max; /**
     * 数据库密码
     */
    private String password; /**
     * 数据库主机地址
     */
    private String url; /**
     * 数据库用户名
     */
    private String user;
    /**
     * 供外部调用的取得数据库连接的方法
     * @param 可用的数据库连接
     */
    public static synchronized Connection getConnection()
    {
    if (instance == null)
    {
    instance = new DBConnectionManager();
    instance.init();
    }
    return instance.getConn();
    } /**
     *读取配置文件内容
     */
    private void init()
    {
    InputStream is = getClass().getResourceAsStream("./db.conf");
    Properties dbProps = new Properties();
    String filename = null;
    freeConnections = new Vector();
    try
    {
    dbProps.load(is);
    }catch (Exception e)
    {
    System.err.println("Can not read config file!");
    return;
    }
    url = dbProps.getProperty("url");
    user = dbProps.getProperty("user","root");
    password = dbProps.getProperty("password");
    String maxConn = dbProps.getProperty("maxconn","50");
    try
    {
    max = Integer.parseInt(maxConn);
    }catch(Exception e){}
    String driverClass = dbProps.getProperty("driver");
    try
    {
    Object obj = Class.forName(driverClass).newInstance();
    DriverManager.registerDriver((Driver)obj);
    }catch(Exception e)
    {
    System.out.println("Can not load driver:"+driverClass);
    }
    } /**
     * 取得一个空闲连接或者新建一个连接
     */
    private Connection getConn()
    {
    Connection con = null;
    if(freeConnections.size() > 0)
    {
    con = (Connection) freeConnections.firstElement();
    freeConnections.removeElementAt(0);
    try
    {
    if (con.isClosed())
    {
    con = newConn();
    }
    }catch (SQLException e)
    {
    return null;
    }
    }else
    {
    if (checkedOut >= max)
    {
    return null;
    }
    con = newConn();
    }
    if (con != null)
    {
    checkedOut++;
    }
    return con;
    } /**
     * 建立一个新的数据库连接
     */
    private Connection newConn()
    {
    Connection con = null;
    try
    {
    if (user == null)
    {
    con = DriverManager.getConnection(url);
    }else
    {
    con = DriverManager.getConnection(url, user, password);
    }
    }catch (SQLException e)
    {
    e.printStackTrace();
    return null;
    }
    return con;
    } /**
     * 释放连接
     */
    public static synchronized void freeConnection(Connection con)
    {
    if (instance == null)
    {
    instance = new DBConnectionManager();
    instance.init();
    }
    instance.freeConn(con);
    } /**
     * ConnectionManager实例释放连接
     */
    private void freeConn(Connection con)
    {
    freeConnections.addElement(con);
    checkedOut--;
    } /**
     * 释放所有连接
     */
    /*
    public synchronized void release()
    {
    Enumeration allConnections = freeConnections.elements();
    while (allConnections.hasMoreElements())
    {
    Connection con = (Connection) allConnections.nextElement();
    try
    {
    con.close();
    }catch (SQLException e)
    {
    e.printStackTrace();
    }
    }
    freeConnections = new Vector();
    checkedOut = 0;
    }*/
    }
    ///:~
    ==================   db.properties  ==========================url=jdbc:mysql://150.0.1.111/beijing?useUnicode=true&charsetEncoding=ISO-8859-1
    driver=org.gjt.mm.mysql.Driver
    user=easyweb
    password=
    maxconn=60
    output=false
      

  4.   

    谢谢,也给我一份吧!急用!
    [email protected]
      

  5.   

    也给我一份吧!先谢谢了。
    [email protected]
      

  6.   

    也给我一份,谢谢
    [email protected]
      

  7.   

    拜托也给我一份!~ 谢谢了
    [email protected]
      

  8.   

    thanks 
    [email protected]
      

  9.   

    那位有的能否给一份?
    谢谢[email protected]