JAVA/JSP

JSP 오라클 Statement

왕왕왕왕 2015. 8. 21. 12:19

<%@ 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();


Statement pstmt = con.createStatement();

int re = pstmt.executeUpdate(sql);

if(re!=0){

out.println("<h2>연결되었습니다.</h2>");

}

                   //모든 자원 close();


} catch (Exception e) {

out.println("<h2>연결실패하였습니다..</h2>");

e.printStackTrace();


}

%>


</body>

</html>