/*************************************************************************/ /* A Simple JDBC Program showing the exucution of a DML statement */ /*************************************************************************/ import java.sql.*; import cs1.Keyboard; class ChangeSalary { public static void main (String args []) throws SQLException { DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); String user, pass, DML; int empid, newSalary; user = "example"; pass = "tiger"; System.out.print("Please enter an employee ID: "); empid = cs1.Keyboard.readInt(); System.out.print("Please enter the new salary: "); newSalary = cs1.Keyboard.readInt(); DML = "UPDATE employees SET salary = " + newSalary + " WHERE empid= '" + empid + "'"; try { Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Neelix:1521:itec",user,pass); Statement stmt = conn.createStatement (); int rowsUpdated = stmt.executeUpdate(DML); System.out.println(""); if (rowsUpdated==1) System.out.println("The following query was successful:"); else System.out.println("No employee with that empid was found:"); System.out.println(DML); conn.close(); } catch (SQLException e){System.out.println ("Database Error: "+e); } /* for(;;); */ } }