
// PlaceHolders.java
// Andrew Davison, October 22nd 2008, ad@fivedots.coe.psu.ac.th

// Update the name of Id 1 in urlInfo: change it to 
// "Andrew Davison"

import java.sql.*;


public class PlaceHolders {

  public static void main(String[] args)
  {
    // The URL for the Books database.
    // It is 'protected' by a login and password.
    String url = "jdbc:odbc:Books";  
    String username = "anonymous";
    String password = "guest";

    try {
      // load the JDBC-ODBC Bridge driver
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

      // connect to the database using the DriverManager
      Connection conn = DriverManager.getConnection( url, username, password );
       
      // Create PreparedStatement
      tring changeAD = "update urlInfo set name = ? where id = ?";
      PreparedStatement ps = conn.prepareStatement(changeAD);

      // Fill in the '?'s
      ps.setString(1, "Andrew Davison");
      ps.setInt(2, 1);   // his id is '1'

      // make the change
      int noRowsUpdated = ps.executeUpdate();
      System.out.println("No. of Rows updated: " + noRowsUpdated);
		
      // Close down
      conn.close();
    } 
    catch ( ClassNotFoundException cnfex ) {
      System.err.println("Failed to load JDBC/ODBC driver." );
      cnfex.printStackTrace();
      System.exit( 1 );  // terminate program
    }
    catch ( SQLException sqlex ) {
      System.err.println( sqlex );
      sqlex.printStackTrace();
    }
  } // end of main()

} // end of PlaceHolders class


