将它改为以下形式并加入Oracle的设置信息 prefix="localhost_DBTest_log." suffix=".txt"timestamp="true"/>
factory
monsdbcpBasicDataSourceFactory
driverClassName
oraclejdbcdriverOracleDriver
url
jdbc:oracle:thin:@::accp
username
scott
password
tiger
maxActive
maxIdle
maxWait
.然后再打D:\tomcat\webapps\myapps\WEBINF\下的webxml加入以下东东(注意要在之前加)
Oracle Datasource example
jdbc/myoracle
javaxsqlDataSource
Container
下面就是写一个JSP代码进入测试了
在D:\tomcat\webapps\myapps\下编写一个testjsp内容如下
<%@ 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();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/myoracle");
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 BOOK");
out.println("
rst is Ok!" + rst.next());
while(rst.next()){
out.println("
BOOK_CODE:" + rst.getString(1));
}
cn.close();
}else{
out.println("rst Fail!");
}
}
else
out.println("Fail!");
}catch(Exception ne){ out.println(ne);
}
%>
最后进入测试运行tomcatbat打开IE在地址栏中输入