try { // Retrieving rows from the database. PreparedStatement stmt = connection.prepareStatement( "SELECT * FROM mytable WHERE COL_A = ?"); int colunm = 1; stmt.setString(colunm, "Patrick Chan"); // Updating the database. stmt = connection.prepareStatement( "UPDATE mytable SET COL_A = ? WHERE COL_B = ?"); colunm = 1; stmt.setString(colunm, "John Doe"); colunm = 2; stmt.setInt(colunm, 123); int numUpdated = stmt.executeUpdate(); }