/* * This sample is equivalent to the other example1 for different interfaces/databases * * It uses the JDBC THIN driver. See the same program in the */ // You need to import the java.sql package to use JDBC import java.sql.*; import java.io.*; class Example1 { public static void main (String args []) throws SQLException { String username="", password=""; BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); try { System.out.print("Username: "); username = in.readLine(); System.out.print("Password: "); password = in.readLine(); } catch(IOException e) { System.out.println("Error: " + e); } System.out.println("Ok, user " + username); // Connect to the database // You must put a database name after the @ sign in the connection URL. // You can use either the fully specified SQL*net syntax or a short cut // syntax as ::. The example uses the short cut syntax. Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@dbserv.dc.umd.edu:1521:SC424", username, password); // Create a Statement Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table ResultSet rset = stmt.executeQuery ("select * from user_tables"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); } }