/* * This sample shows how to list all the names from the EMP table. * * In order for Oracle drivers to be loaded when runing your Java * apps that connect to Oracle, you'll need to modify your CLASSPATH. * Please update your .cshrc file by adding the following to your CLASSPATH: * /opt/oracle/classes12.zip * for example, change from: * setenv CLASSPATH .:/csclass/blue/csc212/classes:$HOME/public-html/classes:... * to * setenv CLASSPATH .:/opt/oracle/classes12.zip:/csclass/blue/csc212/classes:$HOME/public-html/classes:... * * Enter your Oracle UserName/Password when prompted at execution. */ import java.io.*; import java.sql.*; class Employee { public static void main (String args []) throws SQLException, IOException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Get UserName/Password BufferedReader inp = new BufferedReader( new InputStreamReader(System.in)); System.out.print("Enter User Name:"); String user = inp.readLine(); System.out.print("Enter Password:"); String password = inp.readLine(); // Connect to the database. // "ora" is the machine with the oracle server. // SQL Listener is listening on port 1521. // The instance of the database is "csdb". Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:" + user.trim()+"/"+password.trim()+ "@ora.oswego.edu:1521:csdb"); // Create a Statement Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); } }