Java Database Programming Bible- P4

Java Database Programming Bible- P4: Welcome to Java Database Programming Bible. This book is for readers who are already familiar with Java, and who want to know more about working with databases. The JDBC Application Programming Interface has made database programming an important aspect of Java development, particularly where Web applications are concerned. | Chapter 4 Introduction to JDBC 2. Set a new value for each column in the row by using the appropriate update method. 3. Call the method insertRowO to insert the new row into the result set and simultaneously into the database. Listing 4-9 demonstrates the use of the UpdatableResultSet to insert a new row into a database. Listing 4-9 Using UpdatableResultSet to insert a new row Connection con jdbc odbc Contacts Statement stmt ResultSet rs query Contact_ID 150 First_Name Nigel Last_Name Thornebury If you insert a row without supplying a value for every column in the row the default value for the column will be used if there is one. Otherwise if the column accepts SQL NULL values a NULL will be inserted. Failing either of those a SQLException will be thrown. You will also get a SQLException if a required table column is missing in the ResultSet you use to insert the row so the query used to get the ResultSet object should generally select all columns though you will probably want to use a WHERE clause to limit the number of rows returned by your SELECT statement. Caution If you move the cursor from the insert row before calling the method insertRow you will lose all of the values you have added to the insert row. To move the cursor from the insert row back to the result set you can use any of the methods that put the cursor on a specific row first last beforeFirst afterLast and absolute. You can also use the methods previous and relative because the result set maintains a record of the current row while accessing the insert row. In addition you can use a special method moveToCurrentRow which can be called only when the cursor is on the insert row. This method moves the cursor from the insert row back to the row that was .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
272    23    1    30-11-2024
476    18    1    30-11-2024
24    21    1    30-11-2024
Đã 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.