1. 오라클 테이블 생성
create table bbs_jsp
(
num number primary key, --게시판 글
writer varchar2(50), --글쓴이
subject varchar2(50), --제목
content CLOB, --내용
passwd varchar2(60), --비밀번호
reg_date char(14), --작성날짜 시간
ip varchar2(30), --ip
readcount number, --조회수
ref number, --원글
re_step number, --답변글 순서
re_level number --답변글 레벨
);
2. jsp 설정
2.1 server.xml 설정
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="jdbc/orabbs" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
username="유저네임" password="비밀번호" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</GlobalNamingResources>
<Context docBase="MakeBBS" path="/MakeBBS" reloadable="true" source="org.eclipse.jst.jee.server:MakeBBS">
<Resource name="jdbc/orabbs" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
username="유저네임" password="비밀번호" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</Context>
2.2. web.xml 설정
<web-app>
<resource-ref>
<description>Oracle Datasource</description>
<res-ref-name>jdbc/orabbs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
2.3. jar 파일 lib에 추가
3. DB 연결 부분
package BBSBean;
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DBBean {
private static DBBean instance = new DBBean();
public static DBBean getInstance()
{
return instance;
}
private DBBean()
{
}
private Connection getConnection()
{
Connection conn = null;
try {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/orabbs");
conn = ds.getConnection();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return conn;
}
}
4. 참고
4.1 server.xml, web.xml, db연결 부분
http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html 참고
4.2 jar파일
http://commons.apache.org/components.html
\server\jdbc\lib
'기초 > jsp' 카테고리의 다른 글
jstl lib 개요 및 사용방법 (0) | 2015.05.11 |
---|---|
JSTL을 사용하기 위한 라이브러리 추가하기 (0) | 2015.05.11 |
jsp db 컨테이너로 연동 (0) | 2015.04.29 |
JQuery load 성공 실패 (0) | 2015.04.27 |
Redirect (0) | 2015.04.21 |