/* * This sample shows how to retrieve and list all the names * (FIRST_NAME, LAST_NAME) from the EMPLOYEES table * * note: jdk1.2 is recommanded. jdk1.1 will also work */ // You need to import the java.sql package to use JDBC import java.sql.*; class SelectExample { public static void main (String args []) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); String url = "jdbc:oracle:oci8:@"; try { String url1 = System.getProperty("JDBC_URL"); if (url1 != null) url = url1; } catch (Exception e) { // If there is any security exception, ignore it // and use the default } // Connect to the database Connection conn = DriverManager.getConnection (url, "hr", "hr"); // Create a Statement Statement stmt = conn.createStatement (); // Select first_name and last_name column from the employees table ResultSet rset = stmt.executeQuery ("select FIRST_NAME, " + "LAST_NAME from EMPLOYEES"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1) + " " + rset.getString (2)); // Close the RseultSet rset.close(); // Close the Statement stmt.close(); // Close the connection conn.close(); } }