Java Data Access—JDBC, JNDI, and JAXP phần 9

nhân viên thông qua các trình điều khiển JDBC-ODBC, truy vấn tất cả nhân viên và vị trí của mình tên, và các định dạng các hàng nhận được trong một bảng. Để sử dụng kết nối cơ sở dữ liệu trong trang của tôi lần đầu tiên tôi phải nhập khẩu các gói JDBC. | Chapter 17 Building Data-centric Web Applications finally if stmt null if conn null center body html This JSP page connects to the Employees database via the JDBC-ODBC driver queries all employees and their respective location names and formats the rows received in a table. To use database connectivity in my page I must first import the JDBC package. I do this in the @ page. JSP directive element. The following code snippet shows the full tag that I use @ page language java import . This tag also specifies that the language I will be using in the scriptlets is Java. Inside the first scriptlet contained in the . scripting element I perform the standard actions of loading the driver opening a database connection creating a statement and finally querying the database for all the employees and their location names. XRef Chapters 4 through 6 provide detailed information about effectively using JDBC to connect to a database JDBC Statements and JDBC Result Sets. Each employee is returned as a row in the ResultSet I receive as a result of the query. To place the ResultSet data in a table I start an HTML table in the template code and create a header row containing the column names and the sort-arrow graphics. The sort links are dynamically generated based on the column so this is the ideal time to build them. These links are actually links to the page itself with URL parameters that specify the column to sort on and the direction of the sort ascending or descending . Clicking one of these links requests the page itself which re-queries the database using the SORT BY clause to properly order it. I iterate through the ResultSet and create a table row for each database row. Each cell in the row corresponds to the column data. The last column is not populated with data it is reserved for the two action links which I also dynamically build. Edit which is the first action is a link to the page. The Edit Employee page when invoked .

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.