Tomcat 6.0 + Oracle 10 GB Data source connection test

Source: Internet
Author: User

1. Copy the driver package \ product \ 10.2.0 \ db_1 \ jdbc \ lib under the Oracle directory to copy the ojdbc14.jar file to the lib directory under the tomcat directory;

2. server in the tomcat conf directory. insert the following code in <Context path = "/test" docBase = "D: \ Tools \ Project \ test \ WebRoot" reloadable = "true"> </Context>

  1. <Resource Name="Jdbc/chong800"// Data source name
  2. Auth="Container"
  3. Type="Javax. SQL. DataSource"
  4. MaxActive="100"
  5. MaxIdle="10"
  6. MaxWait="10000"
  7. Username="Scott"// Database username
  8. Password="Tiger"// Database Password
  9. DriverClassName="Oracle. jdbc. driver. OracleDriver"
  10. Url="Jdbc: oracle: thin: @ localhost: 1521: chong800"
  11. />

3. Data Source test JSP page

  1. <% @ PageLanguage="Java" ContentType="Text/html; charset = GB18030"
  2. PageEncoding="GB18030"%>
  3. <% @ PageImport="Java. SQL .*"%>
  4. <% @ PageImport="Javax. SQL .*"%>
  5. <% @ PageImport="Javax. naming .*"%>
  6. <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <Html>
  8. <Head>
  9. <Meta Http-equiv="Content-Type" Content="Text/html; charset = GB18030">
  10. <Title>Data Source Test</Title>
  11. </Head>
  12. <Body>
  13. <%
  14. ConnectionConn=Null;
  15. ContextContext=NewInitialContext ();
  16. // Java: comp/env/used only when tomcat is used
  17. DataSourceDts= (DataSource) context. lookup ("java: comp/env/jdbc/chong800 ");
  18. Conn=Dts. GetConnection ();
  19. %>
  20. When conn is null, the data source is not found.
  21. <% = Conn %>
  22. <% Conn. close (); %>
  23. </Body>
  24. </Html>

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.