The doSQL( ) method  The selecter( ) method

Chapter 4: Data Access Using JDBC

The updater( ) method

// A method that updates a certain row of the 'xmp' table.
// This method illustrates prepared statements and parameter markers.

    public static String updater(Connection con)  
           throws Exception {

        String sql = "update xmp set name = ?, home = ? where id = ?";
        int id=1;
        Address home = new Address("123 Main", "98765");  
        String name = "Sam Brown";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, name);
        pstmt.setObject(2, home);
        pstmt.setInt(3, id);
        int res = pstmt.executeUpdate();
        return "performed";
    }




Copyright © 2005. Sybase Inc. All rights reserved. The selecter( ) method

View this book as PDF