package chapter33;

// UpdatingDatabase.java
// Displaying the contents of the authors table.
import java.sql.*;

public class UpdatingDatabase
{
    // launch the application
    public static void main( String args[] )
            throws SQLException, ClassNotFoundException
    {
        // load database driver class
        Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

        // establish connection to database
        Connection connection = DriverManager.getConnection( "jdbc:odbc:Books" );

        // create Statement for update database
        Statement statement = connection.createStatement();

        // UPDATE SQL staement
        statement.executeUpdate("UPDATE authors SET lastName = 'Jones' " +
                "WHERE lastName = 'Smith' AND firstName = 'Sue'");

        // INSERT SQL staement
        statement.executeUpdate("INSERT INTO authors ( firstName, lastName )" +
                " VALUES ( 'Sue', 'Smith' )" );

        // DELETE SQL statement
        statement.executeUpdate("DELETE FROM authorISBN WHERE " +
                " authorID = 2 AND isbn = '0131426443'" );

        // Close the connection
        connection.close();

    } // end main
}  // end class DisplayAuthors
