我正在使用Tomcat5.0.28服务器,按照网上说的方法进行了配置,参考网页地址:http://forums.devshed.com/t120081/s.html 。
1、在$TOMCAT_HOME/common/lib. 下copy Oracle9的jdbc驱动程序classes12.jar classes111.jar
2、在$TOMCAT_HOME/conf/Catalina/localhost/目录下,生成car.xml文件。内容是
<?xml version='1.0' encoding='utf-8'?>
<Context crossContext="true" debug="5" docBase="car" path="/car" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_car_log."
suffix=".txt" timestamp="true"/>
<Resource name="jdbc/gc" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/gc">
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@192.100.10.245:1521:gcrc</value>
</parameter>
<parameter>
<name>validationQuery</name>
<value>select now()</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>username</name>
<value>gc</value>
</parameter>
<parameter>
<name>password</name>
<value>gc</value>
</parameter>
</ResourceParams>
</Context>
3、测试用的jsp页面
<%@ page import='java.sql.*, javax.sql.*, javax.naming.*' %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
//initCtx.bind("jdbc/gc",ds);
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/gc");
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 LOGIN");
out.println("<p>rst is Ok!" + rst.next());
while(rst.next()){