반응형
server.xml
<GlobalNamingResources>
<Resource
auth="Container"
driverClassName="oracle.jdbc.OracleDriver"
initialSize="0"
maxIdle="20"
maxTotal="20"
maxWaitMillis="5000"
minIdle="5"
name="jdbc/oracle"
password="passWord"
url="jdbc:oracle:thin:@localhost:1521:orcl"
username="oracleId"
type="javax.sql.DataSource"
/>
</GlobalNamingResources>
context.xml
<Context>
<ResourceLink
global="jdbc/oracle"
name="jdbc/oracle"
type="javax.sql.DataSource"
/>
</Context>
db pool 소스
public class DBConnPool {
public Connection con;
public Statement stmt;
public PreparedStatement psmt;
public ResultSet rs;
public DBConnPool() {
try {
Context initCtx = new InitialContext();
Context ctx = (Context)initCtx.lookup("java:comp/env");
DataSource source = (DataSource)ctx.lookup("jdbc/oracle");
con = source.getConnection();
System.out.println("DB 커넥션 풀 연결 성공");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void close() {
try {
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(psmt != null) psmt.close();
if(con != null) con.close();
System.out.println("DB 커넥션 풀 자원 반납");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
반응형