... , email); 
114            insertNewPerson.setString(4, phoneNumber); 
115
116            return insertNewPerson.executeUpdate();   
117         }
118         catch (SQLException sqlException) {
119            sqlException.printStackTrace();
120            return 0;
121         }
122      }
123 
124      // close the database connection
125      public void close() {
126         try {
127            connection.close();
128         }
129         catch (SQLException sqlException) {
130            sqlException.printStackTrace();
131         }
132      }
133   }

PreparedStatements used by the Address Book application.

Creating PreparedStatements

Lines 28–29 invoke Connection method prepareStatement to create the Prepared-Statement selectAllPeople that selects all the rows in the Addresses table and sorts them by last name, then by first name. Lines 33–35 create the PreparedStatement selectPeopleByLastName ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.