¾È³çÇϼ¼¿ä.
¾ÆÀÌÁîÀ¥ È£½ºÆà ÀÔ´Ï´Ù.
[server.xml] server.xml¿¡¼ ±âÁ¸ Context ¼³Á¤À» ´ÙÀ½°ú °°ÀÌ º¯°æÇÕ´Ï´Ù.
<Context path="" docBase="www"> <Resource name="jdbc/mytc5" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/dbname" username="dbuser" password="dbpasswd" maxActive="20" maxIdle="10" maxWait="3000"/> </Context>
[web.xml] <resource-ref> <res-ref-name>jdbc/mytc5</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
[jdbctest.jsp] <html> <head> <%@ page errorPage="errorpg.jsp" import="java.sql.*, javax.sql.*, java.io.*, javax.naming.InitialContext, javax.naming.Context" %> </head> <body> <h1>JDBC JNDI Resource Test</h1>
<% InitialContext initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/mytc5"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select version();"); while (rset.next()) { out.println("mysql version=="+rset.getString("version()")); } rset.close(); stmt.close(); conn.close(); initCtx.close(); %> </body> </html>
°¨»çÇÕ´Ï´Ù.
|