This article describes the implementation method of java based on odbc connection oracle. Share it for your reference, as follows:
1. Load the oracle driver
oracle.jdbc.driver.OracleDriver
2. Establish a connection to the given database URL
jdbc:oracle:thin:@localhost:1521:orcl
3. The default username is system, and the password is set by yourself. You cannot use sys or sysdba. This is just a 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"); }}For more information about Java related content, please check out the topics of this site: "Summary of Java Files and Directory Operation Skills", "Tutorial on Java Data Structures and Algorithms", "Summary of Java Operation DOM Node Operation Skills" and "Summary of Java Cache Operation Skills"
I hope this article will be helpful to everyone's Java programming.