|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
作者:Junsan Jin 日期:2003-12-22 版本:1.2 2005-4-4 信箱:junsan21@126.com ; junnef21@sohu.com Blog:http://blog.csdn.net/junnef 声明:本人保留本文的所有权利。 第一部分:预备工作: 第一步: 准确安装Oracle8.1.7数据库,准确创建一个开发使用的数据库,如当前所使用的数据库为192.168.0.1:1521中的dbserver数据库,用户erp。 第二步: 准确安装tomcat5.0.19。 第二部分:正式配置工作 第一步: 找到数据库的驱动程序classes12.zip包,将其重命名为classes12.jar,放到%TOMCAT_HOME%/common/lib下。 第二步: 在%TOMCAT_HOME%/webapps目录下新建一个DBTest目录,并在其下新建一个WEB-INF目录。 第三步: 在%TOMCAT_HOME%/conf目录下找到server.xml文件,找到类似如下的配置部分: <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 在与之对应的</host>标志之中加入如下配置信息: <Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_DBTest_log." suffix=".txt" timestamp="true"/> <Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/myoracle"> <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:@192.168.0.1:1521:dbserver</value> </parameter> <parameter> <name>username</name> <value>erp</value> </parameter> <parameter> <name>password</name> <value>erp</value> </parameter> <parameter> <name>maxActive</name> <value>20</value> </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(); Statement stmt = conn.createStatement(); ResultSet rst = stmt.executeQuery( "select * from cc_tab_kucun");// cc_tab_kucun可以是任意一个表名 if(rst.next()) { foo=rst.getString(1); //bar=rst.getInt(3); } conn.close(); } } }catch(Exception e) { e.printStackTrace(); } %> <html> <head> <title>DB Test</title> </head> <body> <h2>Results</h2> Foo <%= foo %><br/> Bar <%=bar %> </body> </html> 在IE中输入http://localhost:8080/DBTest/DBTest.jsp,假如正常运行显示类似如下所示: Results Foo 3980Bar –1 则说明成功。 返回类别: 教程 上一教程: Jcorb和OpenORB的性能比较 下一教程: JAVA相关基础知识(5) 您可以阅读与"Tomcat5.0.19与oracle8.1.7连接池配置指南"相关的教程: · TOMCAT5+MSSQL SERVER 2000数据库连接池配置之旅 · Tomcat4.1.31的数据库连接池配置 · TOMCAT4的数据库连接池配置 · tomcat+mysql数据库的连接池配置 · Resin2.1.12的数据库连接池配置 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |