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