tailieunhanh - Advanced Java 2 Platform HOW TO PROGRAM phần 4

phương pháp các cuộc gọi phương thức executeUpdate đó là tuyên bố (dòng 211, 226, 237 và 248), trả về một số nguyên chỉ số hàng sửa đổi bởi bản cập nhật. Việc thi hành PreparedStatement mỗi Tiếp theo là một cấu trúc kiểm tra giá trị trả về của executeUpdate. Nếu executeUpdate trả về 0, | Chapter 8 Java Database Connectivity JDBC 499 database and uses that information to set the parameters of PreparedStatements sqlUpdateName lines 208-210 sqlUpdateAddress lines 220-225 sqlUp-datePhone lines 235-236 and sqlUpdateEmail lines 246-247 . Note that parameter values are set by invoking PreparedStatement set methods for the appropriate data type. In this example the ID parameters are all integers and the remaining data are all strings so the program uses methods setInt and setstring to specify parameters. After setting the parameters for a particular PreparedStatement the method calls that statement s executeUpdate method lines 211 226 237 and 248 which returns an integer indicating the number of rows modified by the update. The execution of each Pre-paredStatement is followed by an if structure that tests the return value of executeUpdate. If executeUpdate returns 0 the PreparedStatement did not update any records. Therefore savePerson invokes Connection method rollback to restore the database to its state before the PreparedStatement executed and returns false to indicate to the AddressBook application that the update failed. If savePerson reaches line 256 it commits the transaction in the database and returns true to indicate that the update was successful. CloudscapeDataAccess method newPerson lines 278-367 is similar to method savePerson. Method newPerson receives an AddressBookEntry containing the complete information for a person to insert in the database and uses that information to set the parameters of PreparedStatements sqlInsertName lines 286287 sqlInsertAddress lines 303-313 sqlInsertPhone lines 323-325 and sqlInsertEmail lines 335-337 . The primary difference between newPerson and savePerson is that the entry does not exist in the database yet. To insert rows in tables addresses phoneNumbers and emailAddresses the personID foreign-key field for each new record must correspond to the personID primary-key field in the names table. The new .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.