import java.sql.*;
import java.io.*;

class QueryUnivDB {
    public static void main(String args[]) throws SQLException, IOException {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            System.out.println("Could not load the driver");
        }

        String user = readEntry("Userid : ");
        String pass = readEntry("Password: ");
        Connection conn = DriverManager.getConnection
                                    ("jdbc:oracle:thin:@ten10:1521:acdb", user, pass);
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery
                                    ("select s.sname, c.title from students s, courses c, " +
                                     "enrollments e where s.sid = e.sid and c.cid = e.cid");

        while (rset.next()) {
            System.out.println(rset.getString(1) + ", " + rset.getString(2));
        }
        stmt.close();
        conn.close();
    }
    static String readEntry(String prompt) {
        try {
            StringBuffer buffer = new StringBuffer();
            System.out.print(prompt);
            System.out.flush();
            int c = System.in.read();
            while (c != '\n' && c != -1) {
                buffer.append((char)(c));
                c = System.in.read();
            }
            return buffer.toString().trim();
        } catch (IOException e) {
            return "";
        }
    }
}