Configuration of Oracel database connection pool under JBoss 4.0.5 __ Database

Source: Internet
Author: User
Tags stmt jboss

1. Place the Ojdbc14.jar bag under the $JBOSS _home$/server/default/lib
2. Under the $jboss_home$/server/default/deploy
Create Oracle-ds.xml with the following contents

<?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. Under the $jboss_home$/server/default/deploy
Create the Test.war folder under which you create the test file test.jsp, which reads as follows:

<%@ 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. Create under $jboss_home$/server/default/deploy/test.war
Web.xml file, which reads as follows:

<?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. Create under $jboss_home$/server/default/deploy/test.war
Jboss-web.xml file (no this file will report a JDBC not found error), which reads as follows:

<?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. Perform $jboss_home$/bin Run.bat and run JBOSS. After running, enter in the browser address bar
Http://localhost:8080/test/test.jsp for testing

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.