| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「SCWCD 準備」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「===出題範囲=== http://suned.sun.co.jp/JPN/certification/compobj.html ===開発、検証環境=== =====JDK===== *http://java.sun.com/j2se/1.5.0/ja/download.html *…」)
 
22行目: 22行目:
 
**$CATALINA_HOME/conf/server.xml
 
**$CATALINA_HOME/conf/server.xml
 
**Web アプリケーションの Context に Resource を設定
 
**Web アプリケーションの Context に Resource を設定
  <Host name="localhost"  
+
  &lt;Host name="localhost"  
 
           :
 
           :
     <Context path="/DBTest" docBase="DBTest"
+
     &lt;Context path="/DBTest" docBase="DBTest"
       debug="5" reloadable="true" crossContext="true">
+
       debug="5" reloadable="true" crossContext="true"&gt;
       <Resource name="jdbc/myoracle" auth="Container"
+
       &lt;Resource name="jdbc/myoracle" auth="Container"
 
                 type="javax.sql.DataSource"   
 
                 type="javax.sql.DataSource"   
 
                 driverClassName="oracle.jdbc.OracleDriver"
 
                 driverClassName="oracle.jdbc.OracleDriver"
 
                 url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
 
                 url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
 
                 username="scott" password="tiger" maxActive="20" maxIdle="10"
 
                 username="scott" password="tiger" maxActive="20" maxIdle="10"
                 maxWait="-1"/>
+
                 maxWait="-1"/&gt;
     </Context>
+
     &lt;/Context&gt;
 
           :
 
           :
  </Host>
+
  &lt;/Host&gt;
  
 
*web.xml の設定
 
*web.xml の設定
  <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+
  &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">
+
   version="2.4"&gt;
 
         :
 
         :
   <resource-ref>
+
   &lt;resource-ref&gt;
     <description>Oracle Datasource example</description>
+
     &lt;description&gt;Oracle Datasource example&lt;/description&gt;
     <res-ref-name>jdbc/myoracle</res-ref-name>
+
     &lt;res-ref-name&gt;jdbc/myoracle&lt;/res-ref-name&gt;
     <res-type>javax.sql.DataSource</res-type>
+
     &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
     <res-auth>Container</res-auth>
+
     &lt;res-auth&gt;Container&lt;/res-auth&gt;
   </resource-ref>
+
   &lt;/resource-ref&gt;
 
         :
 
         :
  </web-app>
+
  &lt;/web-app&gt;
  
 
*コードサンプル
 
*コードサンプル

2020年2月15日 (土) 08:05時点における版

出題範囲

http://suned.sun.co.jp/JPN/certification/compobj.html

開発、検証環境

JDK
Document
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, "!J2EE"