Java Server Pages: A Code-Intensive Premium Reference- P6

Java Server Pages: A Code-Intensive Premium Reference- P6:Before you begin reading Pure JSP Java Server Pages, you might want to take a look at its basic structure. This should help you outline your reading plan if you choose not to read the text from cover to cover. This introduction gives you an overview of what each chapter covers. | import . public class SelectDataApp public SelectDataApp public void selectData Connection con null try Load the Driver class file Make a connection to the ODBC datasource Movie Catalog con jdbc odbc Movie Catalog Create the statement Statement statement Use the created statement to SELECT the DATA FROM the Titles Table. ResultSet rs SELECT FROM Titles Iterate over the ResultSet while - 51 - II get the title_name which is a String Title Name title_name II get the rating Title Rating rating II get the price Title Price price II get the quantity Title Quantity quantity n II Close the ResultSet catch lOException ioe catch SQLException sqle catch ClassNotFoundException cnfe catch Exception e - 52 - finally try if con null Close the connection no matter what catch SQLException sqle public static void main String args SelectDataApp selectDataApp new SelectDataApp To execute a query use the same Statement object as in previous examples. You just call a different method. The method to perform a query is executeQuery . Its signature is listed here public ResultSet executeQuery String sql throws SQLException It takes a SQL string like the executeUpdate method. The difference from executeUpdate is that executeQuery returns a ResultSet object containing the results of the query. In our example we passed it the string select from Titles which returns a collection of rows resulting from the query. After we have our ResultSet object returned from executeQuery we can iterate over it. The following code

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
Đã 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.