



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Connection conn = DriverManager.getConnection( "jdbc:oracle:oci8:"+user+"/"+pass); Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("select distinct eno,ename,zip,hdate from employees"); while (rset.next ()) { System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getInt(3) + " " + rset.getDate(4)); } stmt.close(); conn.close(); }
//readEntry function -- to read input string 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 ""; } } }
Other Connection Class Methods
ResultSet
try { some JDBC statement to access the DB; } catch (SQLException e) { System.out.println(“SQL Exception caught!”); while (e!= null) { System.out.println(“Error Message = “ + e.getMessage()); System.out.println(“SQL State = “ + e.getSQLState()); System.out.println(“Error Code = “ + e.getErrorCode()); e = e.getNextException(); } }