[Tomcat] Tomcat 6 JNDI 설정
2010. 5. 28. 11:12ㆍWas/Tomcat
<Resource name="jdbc/OracleTest"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:@localhost:1521:XE"
user="hr"
password="hr"
maxActive="20"
maxIdle="10"
maxWait="-1" />
위 형식으로 다음 두 군데 중 하나에 설정
- context.xml의 <Context>태그사이
- server.xml의 아래쪽 <Context>태그사이
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*, javax.sql.*, javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JNDI Test</title>
</head>
<body>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:/comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/OracleTest");
conn = ds.getConnection();
out.write("<p>DB Connection..</p>");
String sQuery = "SELECT * FROM EMPLOYEES";
stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
while (rs.next()) {
out.write(rs.getString(1) + "<br />");
}
} catch(Exception ex) {
ex.printStackTrace();
} finally {
if (rs != null) try {rs.close(); } catch (Exception ex2) {}
if (stmt != null) try {stmt.close(); } catch (Exception ex3) {}
if (conn != null) try {conn.close(); } catch (Exception ex4) {}
}
%>
</body>
</html>
출처 : http://soriwa.tistory.com/78
'Was > Tomcat' 카테고리의 다른 글
[Tomcat] 톰켓에서 Context Reload를 빨리해보장. (0) | 2010.05.28 |
---|---|
[Tomcat] 톰캣에서 Multiple Instance띄우기. (0) | 2010.05.28 |
[Tomcat] tomcat 6 admin probe (0) | 2010.05.28 |
[Tomcat] tomcat 여러개 띄워보자 AND SSL keystore넣기 (0) | 2010.05.28 |
[Tomcat] Tomcat 로드 밸런싱, 세션 클러스터링 (0) | 2010.05.28 |