java

oracle8i/jdbc/tomcat

aircook 2004. 9. 15. 22:50

os : windows xp

java sdk : j2sdk1.4.2_05

tomcat : Tomcat 4.1.30


oracle8i (8.1.7)


설치된 폴더에 보면..

./jdbc/lib/classes12.zip

이 파일을 확장자를 jar로 바꾼후(tomcat이 zip파일을 인식 못한다나.. 뭐라나..)..

tocat_home/shared/lib에 복사...


classpath... 로 해도 된다던데.. 안해봤다.. 최적화된 방법이 뭔지 아직 모르겠음..


아래 소스는 테스트해본 jsp파일..

<%@page contentType="text/html; charset=euc-kr"%>
<%@page import="java.sql.*"%>

<html>
<head>
<title> 연동 테스트 </title>
<style type="text/css">
body {font-size:9pt; font-family:verdana;}
</style>
</head>
<body>
<center>

<h3>JDBC/JSP Connection TEST</h3>
<%
String url="jdbc:oracle:thin:@localhost:1521:ora817";
String id="scott";
String pass="tiger";

try {
 Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Exception e ) {
 out.println(e);
}

Connection conn=DriverManager.getConnection(url, id, pass);
Statement stmt=conn.createStatement();


String sql="SELECT BALANCE, ACCOUNTNO FROM ACCOUNT";
ResultSet rs=stmt.executeQuery(sql);
%>
<table border="1">
<tr bgcolor="orange">
 <td>이름</td>
 <td>나이</td>
</tr>
<%
while(rs.next()){
%>
<tr>
 <td><%=rs.getInt(1)%></td>
 <td><%=rs.getInt(2)%></td>
</tr>
<%
}

rs.close();
stmt.close();
conn.close();
%>
</table>
</center>
</body>
</html>