- 비동기요청
- 동기요청
요청에 대한 응답 처리 중에 다른 요청이나 일을 할 수 없는 방식
kim@kim-android:~$ sqlplus scott/tiger 다음에 접속됨: Oracle Database 10g SQL> connect sys as sysdba 암호 입력: 연결되었습니다. SQL> show user USER은 "SYS"입니다 SQL> create user javaschool identified by jspproject default tablespace users; SQL> grant connect,resource to javaschool;javaschool 계정에 접속한 후 아래 내용으로 테이블과 시퀀스를 만든다.
-- 회원테이블 create table member ( email varchar2(60) primary key, passwd varchar2(20) NOT NULL, name varchar2(20) NOT NULL, mobile varchar2(20) ); -- 게시판 종류 create table board ( boardcd varchar2(20), boardnm varchar2(40) not null, constraint board_boardcd_pk primary key(boardcd) ); -- 게시글 create table article ( articleno number, boardcd varchar2(20), title varchar2(200) not null, content1 varchar2(4000), content2 varchar2(4000), content3 varchar2(4000), content4 varchar2(4000), content5 varchar2(4000), email varchar2(60), hit number, regdate date, constraint article_articleno_pk primary key(articleno), constraint article_boardcd_fk foreign key(boardcd) references board(boardcd) ); -- 게시글 번호 생성기 create sequence article_articleno_seq increment by 1 start with 1; -- 덧글 create table comments ( commentno number, articleno number, email varchar2(60), memo varchar2(4000), regdate date, constraint comment_commentno_pk primary key(commentno) ); -- 덧글 번호 생성기 create sequence comments_commentno_seq increment by 1 start with 1; -- 첨부파일 create table attachfile ( attachfileno number, filename varchar2(50) not null, filetype varchar2(30), filesize number, articleno number, constraint attachfile_attachfileno_pk primary key(attachfileno) ); -- 첨부파일 번호 생성기 create sequence attachfile_attachfileno_seq increment by 1 start with 1; insert into board values ('free','자유게시판'); insert into board values ('qna','QnA게시판'); insert into board values ('data','자료실'); commit;
<?xml version="1.0" encoding="UTF-8"?> <Context path="/JSPProject" docBase="C:/www/JSPProject/WebContent" reloadable="true"> <Resource name="jdbc/javaschool" auth="Container" type="javax.sql.DataSource" username="javaschool" password="jspproject" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:orcl" /> </Context>
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true"> <session-config> <session-timeout>-1</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <resource-ref> <description>ConnectionPool for JSP Mini Project</description> <res-ref-name>jdbc/javaschool</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %> <% Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; DataSource ds = null; int totalRecord = 0; try { Context ic = new InitialContext(); Context envCtx = (Context) ic.lookup("java:comp/env"); ds = (DataSource) envCtx.lookup("jdbc/javaschool"); } catch (NamingException e) { System.out.println(e.getMessage()); } try { con = ds.getConnection(); String sql = "SELECT count(*) FROM board"; pstmt = con.prepareStatement(sql); rs = pstmt.executeQuery(); rs.next(); totalRecord = rs.getInt(1); } catch (SQLException e) { System.out.println(e.getMessage()); } finally { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DataSource 테스트</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <p> <%=totalRecord %> </p> </body> </html>웹브라우저에서 http://localhost:8080/JSPProject/test.jsp 방문하여 3이 나오면 테스트가 성공한 것이다.