トップ 一覧 ping 検索 ヘルプ RSS ログイン

SCWCD 準備の変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!出題範囲
http://suned.sun.co.jp/JPN/certification/compobj.html
!!開発、検証環境
::JDK
*http://java.sun.com/j2se/1.5.0/ja/download.html
*http://java.sun.com/javaee/downloads/index.html
::Document
*http://java.sun.com/j2ee/1.4/docs/api/index.html
::XML Schemas for J2EE Deployment Descriptors
http://java.sun.com/xml/ns/j2ee/
!TOMCAT
http://tomcat.apache.org/
::document
http://tomcat.apache.org/tomcat-5.5-doc/index.html
::JNDI Datasource
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
*準備
**$CATALINA_HOME/common/lib にJDBCドライバを置く
**Tomcatは、*.jar にしか対応してないので、*.zip なら、リネーム

*server.xml の編集
**$CATALINA_HOME/conf/server.xml
**Web アプリケーションの Context に Resource を設定
 <Host name="localhost" 
          :
    <Context path="/DBTest" docBase="DBTest"
      debug="5" reloadable="true" crossContext="true">
      <Resource name="jdbc/myoracle" auth="Container"
                type="javax.sql.DataSource"  
                driverClassName="oracle.jdbc.OracleDriver"
                url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
                username="scott" password="tiger" maxActive="20" maxIdle="10"
                maxWait="-1"/>
    </Context>
          :
 </Host>

*web.xml の設定
 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">
         :
   <resource-ref>
     <description>Oracle Datasource example</description>
     <res-ref-name>jdbc/myoracle</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
   </resource-ref>
        :
 </web-app>

*コードサンプル
 Context initContext = new InitialContext();
 Context envContext  = (Context)initContext.lookup("java:/comp/env");
 DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
 Connectionconn = ds.getConnection();

----
{{include_html banner_html, "!SCWCD"}}
{{include_html banner_html, "!J2EE"}}