-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdbc.jsp
46 lines (39 loc) · 1.09 KB
/
jdbc.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//1. JDBC 드라이버 로딩하기
Class.forName("oracle.jdbc.driver.OracleDriver");
//2. DB 서버 접속하기
String url = "jdbc:oracle:thin:@localhost:1521:xe";
Connection conn = DriverManager.getConnection(url,"scott","tiger");
//3. Statement or PreparedStatement 객체 생성하기
Statement stmt = conn.createStatement();
//4. SQL 실행
//'test' 테이블 생성
//stmt.executeUpdate("create table test(id varchar2(5), pwd varchar(5))");
/*
//행 삽입
stmt.executeUpdate("insert into test values('aa','11')");
stmt.executeUpdate("insert into test values('bb','22')");
stmt.executeUpdate("insert into test values('cc','33')");
*/
//select
ResultSet rs = stmt.executeQuery("select * from test");
while(rs.next()){
out.println("<br>" + rs.getString("id")+":"+rs.getString(2));
}
//5. 자원해제
rs.close();
stmt.close();
conn.close(); // 연결해제
%>
</body>
</html>