package db;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
public class Conn {
private static Conn instance = new Conn();
public static Conn getInstance() {
return instance;
}
private Conn() {
}
public Connection getConnection() throws SQLException {
Context initContext = null;
try {
initContext = new InitialContext();
// Context envContext = (Context) initContext.lookup("java:comp/env");
// DataSource ds = (DataSource) envContext.lookup("jdbc/oracleDS");
DataSource ds = (javax.sql.DataSource) initContext.lookup ("oracleDS");
return ds.getConnection();
} catch(NamingException e) {
System.out.println("DataSource Err :" + e.toString());
}
return null;
}
public void freeConnection(Connection c, PreparedStatement p, ResultSet r) throws SQLException {
try{
if(r!=null) r.close();
if(p!=null) p.close();
if(c!=null) c.close();
} catch(SQLException e){
e.printStackTrace();
}
}
public void freeConnection(Connection c, Statement s, ResultSet r) throws SQLException {
try{
if(r!=null) r.close();
if(s!=null) s.close();
if(c!=null) c.close();
} catch(SQLException e){
e.printStackTrace();
}
}
public void freeConnection(Connection c, PreparedStatement p) throws SQLException {
try{
if(p!=null) p.close();
if(c!=null) c.close();
} catch(SQLException e){
e.printStackTrace();
}
}
public void freeConnection(Connection c, Statement s) throws SQLException {
try{
if(s!=null) s.close();
if(c!=null) c.close();
} catch(SQLException e){
e.printStackTrace();
}
}
}
'JAVA/JSP' 카테고리의 다른 글
JSP 의 테이블 - > 엑셀로 만들기. (0) | 2008.06.24 |
---|---|
[Java] Singleton 방식에서 객체가 null값이 될때 (0) | 2008.04.02 |
JSP Beans, DTO, DAO, Manager Class, Beans Scope (0) | 2008.03.17 |