/****************************************************************/ /* A Simple JDBC Program using Oracle Database */ /****************************************************************/ import java.sql.*; import java.io.*; class simple { public static void main (String args []) throws SQLException, IOException { try { Class.forName ("com.ms.jdbc.odbc.JdbcOdbcDriver"); //"oracle.jdbc.driver.OracleDriver" //"com.ms.jdbc.odbc.JdbcOdbcDriver" } catch (ClassNotFoundException e) { System.out.println ("Could not load the driver"); } String user, pass; user = readEntry("userid : "); pass = readEntry("password: "); try { Connection conn = DriverManager.getConnection ("jdbc:odbc:order",user,pass); //"jdbc:oracle:thin:@D7RIC1:1521:ORCL" //"jdbc:odbc:order",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)); } conn.close(); }catch (SQLException e){System.out.println ("Could not load the db"+e); } for(;;); } //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 ""; } } }