반응형
<pre>
■ Context의 ChildNode 설정
- 4.*버전대는 server.xml에 설정
- 5.*버전대는 {$catalina_home}/conf/{$domain}/{$context}.xml 파일에 설정
----------------------------------------------------------------------
<Context docBase="C:\web\webroot" debug="0" reloadable="true">
<Resource name="jdbc/Mysql" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="scott" password="tiger" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/codecode?autoReconnect=true" />
</Context>
----------------------------------------------------------------------
■ 해당 어플리케이션의 web.xml의 설정
----------------------------------------------------------------------
<description>MySQL Connection Pool</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/Mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
----------------------------------------------------------------------
■ DataSource로 설정된 DBCP ConnectionPool객체로부터 데이타베이스 커넥션 로드
----------------------------------------------------------------------
import java.util.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
Connection conn = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/Mysql");
conn = ds.getConnection();
}catch(NamingException e) {
e.printStatckTrace();
}
System.out.println(conn);
----------------------------------------------------------------------
</pre>
■ Context의 ChildNode 설정
- 4.*버전대는 server.xml에 설정
- 5.*버전대는 {$catalina_home}/conf/{$domain}/{$context}.xml 파일에 설정
----------------------------------------------------------------------
<Context docBase="C:\web\webroot" debug="0" reloadable="true">
<Resource name="jdbc/Mysql" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="scott" password="tiger" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/codecode?autoReconnect=true" />
</Context>
----------------------------------------------------------------------
■ 해당 어플리케이션의 web.xml의 설정
----------------------------------------------------------------------
<description>MySQL Connection Pool</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/Mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
----------------------------------------------------------------------
■ DataSource로 설정된 DBCP ConnectionPool객체로부터 데이타베이스 커넥션 로드
----------------------------------------------------------------------
import java.util.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
Connection conn = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/Mysql");
conn = ds.getConnection();
}catch(NamingException e) {
e.printStatckTrace();
}
System.out.println(conn);
----------------------------------------------------------------------
</pre>
반응형
'Know > Java' 카테고리의 다른 글
[Eclipse] Absent Line Number Information (0) | 2007.07.23 |
---|---|
api 문서 링크 (0) | 2006.07.20 |
Eclipse에 Tomcat Server플러그인 설치하기 (0) | 2006.05.05 |
[err] ['.' expected]Compilation error in jdk 1.4 later.. (0) | 2006.04.06 |
AIX Java News and FAQ (0) | 2006.03.16 |