JBoss 4.0.5 下Oracel資料庫連接池的配置__資料庫

來源:互聯網
上載者:User

1.將ojdbc14.jar包放到 $JBOSS_HOME$/server/default/lib 下
2.在$JBOSS_HOME$/server/default/deploy下
建立oracle-ds.xml,其內容如下

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc/BSTxDataSource</jndi-name>
    <connection-url>jdbc:oracle:thin:@yourserver:1521:youroracleid</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>yourusername</user-name>
    <password>yourpassword</password>
    <max-pool-size>300</max-pool-size>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
  </local-tx-datasource>
</datasources>

3.在$JBOSS_HOME$/server/default/deploy下
建立test.war檔案夾,在其下建立測試檔案test.jsp,其內容如下:

<%@ page contentType="text/html; charset=gbk" language="java" %>
<%@ page import="javax.naming.Context"%>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
  Context initCtx = new InitialContext();
  Context envCtx = (Context) initCtx.lookup("java:comp/env");
  ds = (DataSource)envCtx.lookup("java:jdbc/BSTxDataSource");
  if(ds!=null){
    out.println("Connection is OK!");
    Connection cn=ds.getConnection();
    if(cn!=null){
       out.println("cn is Ok!");
       Statement stmt = cn.createStatement();
       ResultSet rst = stmt.executeQuery("select * from yourtable");
       out.println("<p>rst is Ok!" + rst.next());
       while(rst.next()){
         out.println("<P>BOOK_CODE:" + rst.getString(2));
       }
       cn.close();
     }else{
       out.println("rst Fail!");
     }
   }
   else
     out.println("Fail!");
%>

4.在$JBOSS_HOME$/server/default/deploy/test.war下建立
web.xml檔案,其內容如下:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <display-name>Welcome to JBoss</display-name>
  <description>
     Welcome to JBoss
  </description>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/BSTxDataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

5.在$JBOSS_HOME$/server/default/deploy/test.war下建立
jboss-web.xml檔案(無此檔案會報jdbc not found錯誤),其內容如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<jboss-web>
  <resource-ref>
    <description>DB Connection</description>
    <jndi-name>java:jdbc/BSTxDataSource</jndi-name>
    <res-ref-name>jdbc/BSTxDataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</jboss-web>

6.執行$JBOSS_HOME$/bin的run.bat,運行jboss。運行後在瀏覽器地址欄中輸入
http://localhost:8080/test/test.jsp進行測試

參考:http://www.theserverside.com/discussions/thread.tss?thread_id=33893
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.