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.