문서의 이전 판입니다!
# cp classes12.jar ~tomcat55/common/lib/ # cp ojdbc14.jar ~tomcat55/common/lib/
<Resource name="jdbc/DBName" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" loginTimeout="10" maxWait="5000" username="아이디" password="비밀번호" testOnBorrow="true" url="jdbc:mysql://localhost:3306/디비이름" />
<resource-ref> <description>MySQL DB Connection</description> <res-ref-name>jdbc/DBName</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
<%@ page contentType="text/html;charset=utf-8" session="true" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>테스트</title>
</head>
<body>
<%
DataSource ds = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/DBName");
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select code_class_id, code_class_name from tb_code_class");
while(rs.next()) {
out.println("Code Class ID: " + rs.getString("code_class_id"));
out.println(", Code Class Name: " + rs.getString("code_class_name") + "<br />");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
out.println("<br /><font color='red'>SQL Exception: " + e + "</font><br/>");
}
%>
</body>
</html>
<%@ page contentType="text/html;charset=utf-8" session="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/DBName">
select code_class_id, code_class_name from tb_code_class
</sql:query>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>테스트</title>
</head>
<body>
<c:forEach var="row" items="${rs.rows}">
ID ${row.code_class_id}<br/>
Name ${row.code_class_name}<br/><br/>
</c:forEach>
</body>
</html>