Use Tomcat + Java JDBC to connect to an Oracle database

Source: Internet
Author: User

First, put the classes12.jar/ojdbc14.jar driver package in the Oracle Installation Directory (D: \ oracle \ product \ 10.2.0 \ db_1 \ jdbc \ lib \) to the tomcat lib directory.

  1. <% @ Page language ="Java" Import="Java. SQL .*"PageEncoding ="GBK"%>
  2. <%! String DBDRIVER ="Oracle. jdbc. driver. OracleDriver";
  3. String DBURL ="Jdbc: oracle: thin: @ localhost: 1521: orcl";
  4. String USERNAME ="Scott";
  5. String PASSWORD ="Orcl";
  6. Connection conn =Null;
  7. Statement stmt =Null; %>
  8. <%
  9. Try{
  10. // Instantiate the driver
  11. Class. forName (DBDRIVER );
  12. Out. println ("The driver has been instantiated! ");
  13. Conn = DriverManager. getConnection (DBURL, USERNAME, PASSWORD );
  14. Out. println ("Connected to the database succeeded! ");
  15. String SQL ="Create table mldntab (name varchar (20 ))";
  16. Stmt = conn. createStatement ();
  17. Stmt.exe cuteUpdate (SQL );
  18. Out. println ("The table has been created !! ");
  19. }Catch(Exception e ){
  20. Out. print ("Database operation problems! Table creation failed! "+ E );
  21. }
  22. %>

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.