拜托,这两个类是自己写的!
J2EE里面有的DATASOURCE类,是现成的连接池!是在javax.sql包下!

解决方案 »

  1.   

    啊,自己写的!好无知呀#◎¥%◎#¥……能不能给一个DATASOURCE类的例子,多谢了,不给例子也一样给分,别误会呀!!
      

  2.   

    websphere下的一段JDBC2.0的连接try {
    //Retrieve a DataSource through the JNDI Naming Service
    java.util.Properties parms = new java.util.Properties();
    parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);
    //Create the Initial Naming Context
    javax.naming.Context ctx = new
    javax.naming.InitialContext(parms);
    //Lookup through the naming service to retrieve a
    //DataSource object
    //In this example, SampleDB is the datasource
    javax.sql.DataSource ds =
    (javax.sql.DataSource)
    ctx.lookup("java:comp/env/jdbc/SampleDB");
    //Obtain a Connection from the DataSource
    java.sql.Connection conn =
    ds.getConnection();
    //query the database
    java.sql.Statement stmt = conn.createStatement();
    java.sql.ResultSet rs =
    stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAME
    FROM EMPLOYEE”);
    //process the results
    while (rs.next()) {
    String empno = rs.getString(“EMPNO”);
    String firstnme = rs.getString(“FIRSTNME”);
    String lastname = rs.getString(“LASTNAME”);
    // work with results
    }
    } catch (java.sql.SQLException sqle) {
    //handle SQLException
    } finally {
    try {
    if (rs != null) rs.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    try {
    if (stmt != null) stmt.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    try {
    if (conn != null) conn.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    }
      

  3.   

    websphere下的一段JDBC2.0的连接try {
    //Retrieve a DataSource through the JNDI Naming Service
    java.util.Properties parms = new java.util.Properties();
    parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory”);
    //Create the Initial Naming Context
    javax.naming.Context ctx = new
    javax.naming.InitialContext(parms);
    //Lookup through the naming service to retrieve a
    //DataSource object
    //In this example, SampleDB is the datasource
    javax.sql.DataSource ds =
    (javax.sql.DataSource)
    ctx.lookup("java:comp/env/jdbc/SampleDB");
    //Obtain a Connection from the DataSource
    java.sql.Connection conn =
    ds.getConnection();
    //query the database
    java.sql.Statement stmt = conn.createStatement();
    java.sql.ResultSet rs =
    stmt.executeQuery(“SELECT EMPNO, FIRSTNME, LASTNAME
    FROM EMPLOYEE”);
    //process the results
    while (rs.next()) {
    String empno = rs.getString(“EMPNO”);
    String firstnme = rs.getString(“FIRSTNME”);
    String lastname = rs.getString(“LASTNAME”);
    // work with results
    }
    } catch (java.sql.SQLException sqle) {
    //handle SQLException
    } finally {
    try {
    if (rs != null) rs.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    try {
    if (stmt != null) stmt.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    try {
    if (conn != null) conn.close();
    } catch (java.sql.SQLException sqle) {
    //can ignore
    }
    }