import java.sql.*; import java.io.*; class Example1 { public static void main (String args []) throws SQLException { String username="", password="",table="" ; BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); try { System.out.println("\nThis Program checks if a connection can be established between Java and Oracle\n"); System.out.println("\nEnter you class UserId and the password. The password is not masked..careful of that! e.g I entered dbclass102 and my password"); System.out.print("Username: "); username = in.readLine(); System.out.print("Password: "); password = in.readLine(); System.out.print("Enter the name of a table which is present in your database: "); table = in.readLine(); } catch(IOException e) { System.out.println("Error: " + e); } System.out.println("Ok, user " + username); // Connect to the database Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@database.grace.umd.edu:1521:dbclass1", username, password); // Create a Statement Statement stmt = conn.createStatement (); // Execute the query ResultSet rset = stmt.executeQuery ("select * from "+table); // Iterate through the result and print the results while (rset.next ()) System.out.println (rset.getString (1)); } }