-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdbc_prepared.jsp
36 lines (29 loc) · 914 Bytes
/
jdbc_prepared.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
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*, java.util.*, job.study.beans.MemberBean" %>
<!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");
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
//Statement
Statement stmt = conn.createStatement();
stmt.executeUpdate("insert into test values('"+id+"', '"+pwd+"')");
//PreparedStatement
PreparedStatement pstmt = conn.prepareStatement("insert into test (id, pwd) values(?, ?)");
pstmt.setString(1, id);
pstmt.setString(2, pwd);
pstmt.executeUpdate();
%>
</body>
</html>