TOMCAT7 configuration Data Source (Oracle)

Source: Internet
Author: User

Modify.. /conf/content.xml

<?XML version= ' 1.0 ' encoding= ' utf-8 '?><!--The contents of this file is loaded for each Web application -<Context>    <!--Default set of monitored resources -    <Watchedresource>Web-inf/web.xml</Watchedresource>    <!--uncomment this to disable session persistence across Tomcat restarts -    <!--<manager pathname= ""/> -    <!--uncomment this to enable Comet connection tacking (provides events in session expiration as well as WebApp Li Fecycle) -    <!--<valve classname= "Org.apache.catalina.valves.CometConnectionManagerValve"/> -    <Resourcename= "Jdbc/oracle"Auth= "Container"type= "Javax.sql.DataSource"Driverclassname= "Oracle.jdbc.OracleDriver"URL= "Jdbc:oracle:thin: @IP: 1521:orcl"username= "username"Password= "Password"maxactive= "5"Maxidle= "2"maxwait= "10000" /></Context>

and copy the Ojdbc6.jar to the Tomcat Lib directory, and the above is configured with the Oracle data source.

When you use it, you need to include it in Web. xml:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:web= "Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"ID= "webapp_id"version= "2.5">    <Display-name>Hpms</Display-name>    <welcome-file-list>        <Welcome-file>index.jsp</Welcome-file>    </welcome-file-list>
<!--Add the following content to Web. xml<Resource-ref> <Description>Java JDBC</Description> <Res-ref-name>Jdbc/oracle</Res-ref-name> <Res-type>Javax.sql.DataSource</Res-type> <Res-auth>Container</Res-auth> </Resource-ref></Web-app>

Instance:

index.jsp

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%@ Page Import="java.sql.*,javax.sql.*,javax.naming.*"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><title>My JSP ' tomcattest.jsp ' starting page</title></Head><Body>    <%Context CTX= NewInitialContext (); DataSource DS=(DataSource) ctx. Lookup ("java:comp/env/jdbc/oracle"); Connection Con=ds.getconnection (); Statement St=con.createstatement (); ResultSet RS=St.executequery ("SELECT * from VendorClass");  while(Rs.next ()) {out.println ("" +rs.getstring (2) + "");        } rs.close ();        St.close ();    Con.close (); %></Body>

Browser access:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.