JSP MySql 커넥션풀 설정정보

JSP MySql 커넥션풀 설정정보


필요한 jar파일을 라이브러리에 복사
-commons-dbcp-1.2.1.jar
-commons-collections-3.1.jar
-commons-pool-1.2.jar
위의 jar를 톰캣의 디렉토리에 복사

톰켓의 lib폴더에 복사후 톰켓의 WEB-INF/lib폴더에 복사
-mysql-connector-java-5.0.0-beta-bin.jar(MYSQL)
-ojdbc14.jsp(오라클)

위의 jar를 자바 디렉토리/jre/lib/ext에 복사

tomcat의 server.xml
server.xml 파일

1
2
3
4
5
6
7
8
9
10
11
12
<GLOBALNAMINGRESOURCES style="TEXT-ALIGN: left; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 12px/16px Tahoma; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(85,85,85); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"></GLOBALNAMINGRESOURCES>안에<GlobalNamingResources>테그안에 또한<Context>테그안에 삽입
<Resource name="jdbc/jsp"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
loginTimeout="10"
maxWait="5000"
username="root"
password="1234"
testOnBorrow="true"
url="jdbc:mysql://localhost:3306/java"
/>

tomcat의 web.xml파일안에 테그안에 삽입

1
2
3
<resource-ref>
<description>Container</description><res-ref-name>jdbc/jsp</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth>
</resource-ref>

커넥션 풀

1
2
3
4
5
6
7
8
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/jsp");
conn = ds.getConnection();

Share