- 접속예제
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String url="jdbc:oracle:thin:@localhost:1521:TESTDB";
String uid="kecon";
String pwd="tiger";
String sql="select * from member";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//JDBC 드라이버를 로드
Class.forName("oracle.jdbc.driver.OracleDriver");
//데이타베이스 연결 객체인 Connection을 생성
conn = DriverManager.getConnection(url, uid, pwd);
//Statement 객체로 executeQuery() 매서드를 실행
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
out.println(rs.getString("name")+"<br>");
}
if(rs !=null) rs.close();
%>
</body>
</html>
- 첨부파일 : ojdbc5.jar
해당 Dynamic Web Project > WebContent > WEB-INF > lib에 추가
'Web > JSP' 카테고리의 다른 글
JSP #20 DBCP (0) | 2015.02.17 |
---|---|
JSP #19 Oracle DB - #2 PreparedStatement (0) | 2015.02.15 |
JSP #17 JSTL-3 fmt 라이브러리 (0) | 2015.02.12 |
JSP #16 sendRedirect & forward (0) | 2015.02.06 |
JSP #15 Servlet에서 입력값 한글 지원 (0) | 2015.02.05 |