import java.io.*; import java.util.*; import java.sql.*; public class showAll { static final String DbURL = "jdbc:oracle:thin:@dbclass.intro.cs.cmu.edu:1521:dbintro"; //Oracel server at cs.cmu static final String OraDriver = "oracle.jdbc.driver.OracleDriver"; //Oracle driver // IMPORTANT: // PUT YOUR USER/PASSWD HERE: // USER-ID: your-andrew-ID; // PASSWD: // // static final String User = ""; // static final String Passwd = ""; static final String fileName="PC.txt"; //file name for text data public static void main(String[] args) { Connection con = null; try { // Load the Oracle Driver Class.forName(OraDriver); // Get a Connection to the database con = DriverManager.getConnection(DbURL, User, Passwd); // Create a Statement object Statement stmt = con.createStatement(); // Create a table named as PC (varchar2(10), varchar2(10)); String sqlSt = "SELECT * FROM PC"; stmt.executeQuery(sqlSt); // ResultSet rs = stmt.executeQuery(sqlSt); while (rs.next()) { System.out.println( rs.getString("parent") + ";" + rs.getString("child") ); } // // in.close(); // con.commit(); } catch (ClassNotFoundException e) { System.out.println("Could not load database driver: " + e.getMessage()); } catch (SQLException e) { System.out.println("SQLException caught : " + e.getMessage()); } catch (Exception e) { System.out.println("Other Exception caught : " + e.getMessage()); } finally { // Always close the database connection try { if (con != null) con.close(); } catch (SQLException ignored) {} } } //end of main } //end of class