SERVER
server.xml
<Context docBase="WebJava" path="/WebJava" reloadable="true" source="org.eclipse.jst.j2ee.server:WebJava">
      <Resource name="jdbc/oracle" auth="Container"
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
              username="scott" password="tiger" maxActive="20" maxIdle="10"
              maxWait="-1"/>
      </Context>

Project(WebJava)
web.xml
<resource-ref>
  <res-ref-name>jdbc/oracle</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>

Connection 객체

import java.sql.Connection;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ServiceUtil {
 static Connection con;
 public static Connection getConnection() {
  Context initContext;
  try {
   initContext = new InitialContext();
   Context envContext  = (Context)initContext.lookup("java:/comp/env");
   DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");
   con = ds.getConnection();
  } catch (Exception e) {
   e.printStackTrace();
  }
  return con;
 }
}



파일복사( ojdbc14.jar, ibatis-2.3.4.726.jar)
Project
web-inf/lib
 
Tomcat
~\Tomcat 5.5\common\lib



'Programing > JSP' 카테고리의 다른 글

JSP EL태그 안될때  (0) 2010.01.20
ibatis 설정  (0) 2010.01.14
JDBC DB설정  (0) 2010.01.14
Struts 설정  (0) 2009.12.21

+ Recent posts