解决方案 »

  1.   


    public class DB {
        private static String url="jdbc:oracle:thin:@localhost:1521:orcl";
    private static String user="scott";
    private static String password="tiger";
        private DB(){ }
        static{
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
    throw new ExceptionInInitializerError(e);
    }
    }

    public static Connection getConnection() throws SQLException{
    return DriverManager.getConnection(url,user,password);
    }

    public static void Free(Connection conn,PreparedStatement ps,ResultSet rs){
    try {
    rs.close();

    catch (SQLException e) 
    {
    }
    try {
    ps.close();

    catch (SQLException e) 
    {
    }
    try {
    conn.close();

    catch (SQLException e) 
    {
    }
    }在别的类中当需要关闭Connection时调用DB.free(conn,ps,rs);
      

  2.   

    求帮助 http://bbs.csdn.net/topics/390797939?page=1#post-397461517
      

  3.   

    你在其它类中连接数据库:
    定义一个Connection conn = DB.getConnection();try{
        Connection conn = DB.getConnection();
    }finally{
        if(conn!=null){
            conn.close(); 
        }
    }在这里关闭的conn就是你原先类中的连接。