환경 : 이클립스, JDK1.6, Tomcat6.0, ORACLE 10g
1. tomcat에 server.xml에 해당 context에 resource 추가
2. 웹프로젝트 디렉토리에 JDBCTest.jsp 파일 추가
JDBCTest.jsp 내용
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<%@ page contentType="text/html;charset=euc-kr" %>
<%@ page import="db.*" %>
<%
Context initContext = null;
Context envContext = null;
DataSource ds = null;
Connection conn = null;
java.sql.Statement stmt = null;
ResultSet rs = null;
String sql = "";
try {
initContext = new InitialContext();
envContext = (Context) initContext.lookup("java:comp/env");
ds = (DataSource) envContext.lookup("jdbc/bbs");
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT count(*) num FROM dual");
while(rs.next())
{ out.println(rs.getString("num")); }
rs.close();
stmt.close();
} catch( Exception e ) {
out.println(e);
} finally {
try { if(rs != null) rs.close(); } catch (Exception e) {}
try { if(stmt != null) stmt.close(); } catch (Exception e) {}
try { if(conn != null) conn.close(); } catch (Exception e) {}
}
%>
서버 구동후 JDBCTest.jsp를 호출하여 결과페이지에 "1"이 출력되면 이상없이 연결완료.
'웹개발' 카테고리의 다른 글
| [JSP] page 디렉티브 속성 trimDirectiveWhitespaces (0) | 2011.03.29 |
|---|---|
| [JAVA] decomiler 디컴파일러 (0) | 2011.03.27 |
| [jQuery/Core/기본/기초 ] Selectors ( 객체 가져오기 ) (0) | 2011.03.04 |
| [TOMCAT] UTF-8 설정시 한글깨짐 (1) | 2011.02.15 |
| [JAVA/Servelet] Dynamic Web Modules ? (0) | 2011.02.01 |
JDBCTest.jsp