|
</parameter><parameter> <name>maxIdle</name> <value>10</value> </parameter> <parameter> <name>maxWait</name> <value>-1</value> </parameter> </ResourceParams> </Context> 第四步: 在当前DBTest的目录下的WEB-INF文件夹下,新建一个web.xml文件,在<web-app></web-app>标记之间加入如下代码: <resource-ref> <description>Oracle Datasource example</description> <res-ref-name>jdbc/myoracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> 新建的文件需要有: <?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"> 说明。 完整文件如下: <?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> <resource-ref> <description>Oracle Datasource example</description> <res-ref-name>jdbc/myoracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> 第五步: 创建一个测试文件放到DBTest目录下:DBTest.jsp <%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <% String foo = "Not Connected"; System.out.println("###"+foo); int bar = -1; try{ Context initContext = new InitialContext(); System.out.println("###" + initContext); Context envContext = (Context)initContext.lookup("java:/comp/env"); System.out.println("###"+ envContext); DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle"); System.out.println("###" + ds); if (ds != null) { Connection conn = ds.getConnection(); System.out.println("###" + conn); if(conn != null) { foo = "Got Connection "+conn.toString(); 上一页 [1] [2] [3] 下一页 [系统软件]EXP-00008: ORACLE error 904 encountered的解决方… [常用软件]PB7 连接 Oracle 的配置方法 [Web开发]oracle Export and Import 简介 [Web开发]ADO访问Oracle结果集的心得 [JAVA开发]JDBC+Hibernate将Blob数据写入Oracle [JAVA开发]J2EE应用中与Oracle数据库的连接 [JAVA开发]Oracle Application Serve_ [其他]HP-UXrx2600B.11.22Uia64安装oracle9i9.2foria64手… [其他]在RedhatEnterpriseserver3上安装oracle9iR2的注意… [其他]PROC++批量导入导出ORACLE数据库表
|