-
import java.sql.Connection;
-
import javax.naming.Context;
-
import javax.naming.InitialContext;
-
import javax.naming.NamingException;
-
import javax.sql.DataSource;
-
-
import java.sql.ResultSet;
-
import java.sql.PreparedStatement;
-
import java.sql.Statement;
-
-
-
public class DBConnection {
-
-
public DBConnection() {
-
-
}
-
-
public Connection getConnection() throws Exception {
-
return getConnection("jdbc/ibisDS");
-
}
-
-
public Connection getConnection(String dsName) throws Exception {
-
Context ctx = null;
-
DataSource ds = null;
-
try {
-
ctx = new InitialContext();
-
ds = (DataSource) ctx.lookup(dsName);
-
} catch (NamingException e) {
-
e.printStackTrace();
-
return null;
-
} finally {
-
try {
-
if (ctx != null)
-
ctx.close();
-
} catch (NamingException ne) {
-
System.err.println("comm.util.conPoool : can't close context resource !!");
-
}
-
}
-
return (Connection) ds.getConnection();
-
}
-
-
public void disConnection(ResultSet rs, PreparedStatement pstmt, Statement cstmt, Connection conn) {
-
try { if(rs != null) rs.close() ; rs = null; } catch(Exception e) { rs = null;}
-
try { if(pstmt!= null) pstmt.close(); pstmt = null; } catch(Exception e) { pstmt = null;}
-
try { if(cstmt!= null) cstmt.close(); cstmt = null; } catch(Exception e) { cstmt = null;}
-
try { if(conn != null) conn.close() ; conn = null; } catch(Exception e) { conn = null;}
-
}
-
}