<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@page import="java.sql.*"%>
<%@page import="javax.sql.*"%>
<%@page import="javax.naming.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
Connection con = null;
String sql = "insert into student(num,name) values(6,'king')";
String[] arr = { "홈길동", "뽀로로", "배트맨" };
try {
Context init = new InitialContext();
DataSource ds = (DataSource) init.lookup("java:comp/env/jdbc/OracleDB");
con = ds.getConnection();
PreparedStatement pstmt = con.prepareStatement("insert into student(num,name) values(?,?)");
for (int i = 0; i < 3; i++) {
pstmt.setInt(1, i);
pstmt.setString(2, arr[i]);
pstmt.executeUpdate();
//한번 입력했을때마다 executeUpdate()를 해줘야 전송한다.
}
//모든 자원 close();
out.println("<h2>연결되었습니다.</h2>");
} catch (Exception e) {
out.println("<h2>연결실패하였습니다..</h2>");
e.printStackTrace();
}
%>
</body>
</html>
'JAVA > JSP' 카테고리의 다른 글
JSP 오라클 ResultSet (0) | 2015.08.24 |
---|---|
JSP 오라클 Statement (0) | 2015.08.21 |
JSP 커넥션풀 속성 (0) | 2015.08.21 |
JSP 커넥션풀 연결 하기 (0) | 2015.08.21 |
JSP 커넥션풀 web.xml 내용추가 (0) | 2015.08.21 |