大家看看我的数据源配置哪里有错误
我的项目目录
D:\DBTEST
|---WEB-INF
| |--web.xml
|--dbtest.jsp
1.在%tomcat_home%\common\lib下拷贝了oracle的数据包classes12.jar
2.安装了oracle10g,端口号1158,数据库名orcl
3.conf/server.xml配置如下:
<Context path= "/test " docBase= "D:\dbtest "
debug= "1 " reloadable= "true " crossContext= "true ">
<Resource name= "jdbc/orcl "
auth= "Container "
type= "javax.sql.DataSource "/>
<ResourceParams name= "jdbc/orcl ">
<parameter>
<name> factory </name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </value>
</parameter>
<parameter>
<name> driverClassName </name>
<value> oracle.jdbc.driver.OracleDriver </value>
</parameter>
<parameter>
<name> url </name>
<value> jdbc:oracle:thin:@localhost:1158:ORCL </value>
</parameter>
<parameter>
<name> username </name>
<value> teacher </value>
</parameter>
<parameter>
<name> password </name>
<value> teacher </value>
..其他参数略..
</ResourceParams>
</Context>
4.web.xml配置如下:
<resource-ref>
<description> 数据源 </description>
<res-ref-name> jdbc/orcl </res-ref-name>
<res-type> javax.sql.DataSource </res-type>
<res-auth> Container </res-auth>
</resource-ref>
5.dbtest.jsp代码如下:
<%@ page language= "java " contentType= "text/html;charset=gb2312 "%>
<%@ page import= "javax.naming.* " %>
<%@ page import= "java.sql.* " %>
<%@ page import= "javax.sql.* " %>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=ISO-8859-1 ">
<title> Insert title here </title>
</head>
<body>
<%
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup( "java:comp/env ");
DataSource ds = (DataSource)envCtx.lookup( "jdbc/orcl ");
Connection con = ds.getConnection();
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery( "select * from student ");
while (rs.next())
{
System.ou