Oracle: A table-based declarative interface to data (SQL)
JDBC: A bridge between these two worlds ... Java + persistent data
Alternatives: ObjectStore, PJama, J++ & ODBC, ...
import java.sql.*; ... Statement s = ... // Run SQL query to fetch data ResultSet r = s.executeQuery("select name from Employees"); // Iterate through result set while (r.next()) System.out.println(r.getString("name")); ...
import java.sql.*; ... Statement s = ... // Generate update command int lowPay = 20000; String sackWorkers = "delete Employees where salary < "+lowPay; // Run SQL update to modify data int nr = s.executeUpdate(sackWorkers); // Indicate update effect System.out.println(nr + " employees laid off"); ...
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver);
or
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(URL, Username, Password);
Username
and Username
are the ones for your Oracle account.
The URL
specifies:
jdbc
)
oracle
)
thin
, oci7
, oci8
)
Host:Port:Database
)
jdbc:oracle:thin:@dingo:1521:cse1
or
jdbc:oracle:oci7:@(DESCRIPTION = (ADDRESS_LIST=(PROTOCOL=TCP)(Host=dingo)(Port=1521)) (CONNECT_DATA=(SID=cse1)))
Statement
.
Each Statement
is attached to a Connection
.
Statement s = conn.createStatement();
Multiple Statement
s can be handled by a Connection
.
Transactions are also handled by the Connection
.
conn.commit();
All transactions are committed and all Statement
s are closed
when a Connection
closes.
export CLASSPATH=/home/oracle/jdbc/lib/classes111.zip:.
For JDBC OCI7 Driver, also need:
export LD_LIBRARY_PATH=/home/oracle/jdbc/lib export NLS_LANG=AMERICAN_AMERICA.US7ASCII
Reminder: use setenv
form csh or tcsh.
Produced: 28 Apr 99