How to connect to an Oracle database using the JDBC data source connection pool

Source: Internet
Author: User

JAVA can be used to connect to the Oracle database through the JDBC data source connection pool. This method is described in detail below. If you are interested in connecting to the Oracle database using JAVA, take a look.

 
 
  1. High database connection efficiency using JDBC data source connection pool)
  2.  
  3. Before connecting to the database in this way, you must first configure the file \ tomcat5 \ conf \ context. xml in the TOMCAT server directory:
  4.  
  5. <Context reloadable = "true">
  6.  
  7. <WatchedResource> WEB-INF/web. xml </WatchedResource>
  8.  
  9. <Resource name = "jdbc/oracle" auth = "Container" type = "javax. SQL. DataSource"
  10. MaxActive = "100" maxIdle = "30" maxWait = "10000" username = "scott" password = "tiger"
  11.  
  12. DriverClassName = "oracle. jdbc. OracleDriver"
  13. Url = "jdbc: oracle: thin: @ 192.168.1.3: 1521: ora92"/>
  14.  
  15. </Context>
  16.  
  17. After configuration, copy the oracle Driver Class classes12.jar to the \ tomcat5 \ common \ lib directory. I have encountered this problem and finally solved it. Previously, when I used the ojdbc5.jar driver class file, I was always unable to establish a connection, and the following problem occurs: Cannot create JDBC oracle driver of class ''for connect url' jdbc: oracle: thin: @ 192.168.1.3: 1521: ora92 '". I hope this article will give readers some inspiration. My QQ number: 89262840
  18.  
  19. Import javax. naming. Context;
  20. Import javax. naming. InitialContext;
  21.  
  22. Import javax. SQL. DataSource;
  23.  
  24. String SQL = "insert into users (username, password) values (?,?) ";
  25.  
  26. String username = request. getParameter ("username ");
  27.  
  28. Try {
  29.  
  30. Context context = new InitialContext ();
  31. DataSource ds = (DataSource) context. lookup ("java:/comp/env/jdbc/oracle ");
  32. Connection conn = ds. getConnection ();
  33.  
  34. PreparedStatement ps = conn. prepareStatement (SQL );
  35.  
  36. Ps. setString (1, StringUtil. filterHtml (username ));
  37. Ps. setString (2, StringUtil. filterHtml (request. getParameter ("password ")));
  38. Result = ps.exe cuteUpdate ();
  39. Ps. close ();
  40. Conn. close ();
  41.  
  42. } Catch (NamingException e ){
  43. E. printStackTrace ();
  44. } Catch (SQLException e ){
  45. E. printStackTrace ();
  46. }
  47.  

The preceding section describes how to connect to an Oracle database using the JDBC data source connection pool.

C # connect to the Oracle database to query data

Connect to the Oracle database through the OCI8 Interface

Instances that use oracle Stored Procedure Paging

Oracle RMAN backup Optimization

Oracle backup using RMAN

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.