1。从www.jboss.org上下载一个jboss-3.2.5的zip包。
2。从www.jarkata.org上下载一个struts的例子,当作deploy下面的一个war包。D:/jboss/server/default/deploy/struts.war
3。修改D:/jboss/bin中run.bat文件
set JAVA_HOME=C:/jdk
4。从D:/jboss/docs/examples/jca中找到oracle-ds.xml修改。
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: oracle-ds.xml,v 1.1.2.4 2003/09/17 03:46:01 ejort Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Oracle originally from Steven Coy -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@10.1.101.138:1521:zhdb</connection-url>
<!--
Here are a couple of the possible OCI configurations.
For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm
<connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
or
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
Clearly, its better to have TNS set up properly.
-->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>zhtb</user-name>
<password>zhtb</password>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
</local-tx-datasource>
</datasources>
5。将oracle-ds.xml修改后放置在D:/jboss/server/default/deploy
6。将oracle数据库驱动程序classes12.zip放置到D:/jboss/server/default/lib中
7。在D:/jboss/server/default/deploy/struts.war中放置一个新的jsp文件testlq.jsp
8。修改testlq.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<html>
<head><title>this is test</title></head>
<%
try
{
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup("java:/OracleDS");
Connection dbConnection = dataSource.getConnection();
PreparedStatement pstmt = null;
ResultSet result = null;
String queryStr = "SELECT OID FROM T_ORDER";
dbConnection = dataSource.getConnection();
pstmt = dbConnection.prepareStatement (queryStr);
result = pstmt.executeQuery();
while(result.next()){
out.println(""+result.getLong("OID"));
}
}
catch (NamingException ne)
{
throw new SQLException("Naming Exception while looking " +
" up DataSource Connection " +
": /n" + ne.getMessage());
}
%>
</html>
9。访问http://10.1.101.138/struts/testlq.jsp