/*
 * This sample shows how to list all the names from the EMP table
 */

// You need to import the java.sql package to use JDBC
import java.sql.*;

class Update
{
  public static void main (String args [])
  {
    // Load the Oracle JDBC driver
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {
      System.out.println ("Oracle device driver does not exist");
      System.exit(0);
    }

    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn=null;
    try {
       conn = 
         DriverManager.getConnection ("jdbc:oracle:thin:@oradev:10521:D", "rramos", "raul");
 
       // Create a Statement
       Statement stmt = conn.createStatement ();

       conn.setAutoCommit(false);
       String s = "update COFFEES set PRICE=1.99 where COF_NAME='Espresso'";
       int r = stmt.executeUpdate (s);

       r+=stmt.executeUpdate ("update COFFEES set PRICE=1.99 where COF_NAME='French'");
       conn.commit();
       System.out.println(r+" rows where updated/modified");
       stmt.close(); conn.close();

    } catch (SQLException e) {
       if (conn!=null) {
          try {
            conn.rollback();
            System.out.println("Error ocurred. Transaction aborted");
          } catch (SQLException rb) {
            System.out.println("Could roll back "+rb.getMessage());
          }
       }
       e.printStackTrace();
    }
  }
}
