일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- PLSQL
- 선택적조인
- 가우스
- JSON
- oracle
- ibsheet
- GPS
- appspresso
- Struts
- Google Map
- node.js
- tomcat
- jsr 296
- 전자정부프레임워크
- PHP
- Android
- WebLogic
- JDOM
- iBATIS
- MFC
- Eclipse
- Spring
- rowspan
- sencha touch
- phonegap
- MySQL
- Ajax
- jQuery
- swingx
- dock
Archives
- Today
- Total
Where The Streets Have No Name
[tomcat]Data Source를 사용해서 DB접속하기 본문
출처 : http://hjazz.com/tt/blog/20
1. tomcat home/conf/server.xml 파일에서 다음과 같은 부분을 추가 해준다.
2. tomcat home/conf/catalina/localhost에 있는 .xml파일을 열어서 Context 태그 내에 다음링크를 추가시킨다.
3. DAO 클래스에서 getConnection 메서드를 구현해서 사용한다. (예)
1. tomcat home/conf/server.xml 파일에서 다음과 같은 부분을 추가 해준다.
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource auth="Container"
driverClassName="oracle.jdbc.driver.OracleDriver" (오라클의 경우)
maxActive="2"
maxIdle="2"
maxWait="5000"
name="jdbc/myDatabase"
password="password"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:@ip address:port number:ora9"(예)
username="username"/> (빨간부분을 설정한다)
2. tomcat home/conf/catalina/localhost에 있는 .xml파일을 열어서 Context 태그 내에 다음링크를 추가시킨다.
<ResourceLink global="jdbc/myDatabase" name="jdbc/myDatabase"
type="javax.sql.DataSource" />
3. DAO 클래스에서 getConnection 메서드를 구현해서 사용한다. (예)
private static Connection getConnection() throws NamingException, SQLException{
InitialContext ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/myDatabase");
return ds.getConnection();
}