Java-based implementation method for Oracle connection _java

Source: Internet
Author: User
Tags stmt

The examples in this article describe the Java-based ODBC-connected Oracle implementation approach. Share to everyone for your reference, specific as follows:

1. Load Oracle Driver

Oracle.jdbc.driver.OracleDriver

2. Establish a connection to a given database URL

Jdbc:oracle:thin: @localhost: 1521:ORCL

3, The default username is System, the password is set by itself, not in SYS or SYSDBA, this is just the role.

public void Testoracle () {
    try {
      class.forname ("Oracle.jdbc.driver.OracleDriver");
      Connection conn = drivermanager.getconnection (
          "Jdbc:oracle:thin: @localhost: 1521:orcl", "System", "admin");
      SYSTEM.OUT.PRINTLN ("Connection successful!") ");
      Statement stmt = Conn.createstatement ();
      ResultSet rs = stmt.executequery ("SELECT * from Stu_info_tab");
      while (Rs.next ()) {
        System.out.println ("OK");
        System.out.println (Rs.getint ("student_id"));
      }
      Rs.close ();
      Stmt.close ();
      Conn.close ();
    } catch (ClassNotFoundException e) {
      System.out.println ("ClassNotFoundException");
    } catch (SQLException e) {
      System.out.println ("SQLException");
    }


More about Java-related content readers can view the site topics: "Java files and directory operation tips Summary", "Java Data structure and algorithm tutorial", "Java Operation DOM node skills summary" and "Java Cache Operation Tips Summary"

I hope this article will help you with Java programming.

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.