tailieunhanh - Java Server Pages 2nd Edition phần 8
Trong chương cuối cùng này, chúng ta hãy xem xét kỹ hơn các chiến lược cho việc sử dụng một cơ sở dữ liệu trong một ứng dụng web mà tôi đã đề cập trong các chương trước. Trong trường hợp bạn là người mới để truy cập cơ sở dữ liệu Java, chúng tôi bắt đầu với một tổng quan về các quan trọng nhất của JDBC các lớp học và giao diện. | Chapter 23. Database Access Strategies Chapter 23. Database Access Strategies In this final chapter we take a closer look at the strategies for using a database in a web application that I ve mentioned in the previous chapters. In case you re new to Java database access we start with a brief overview of the most important JDBC classes and interfaces. Next we focus in on the JDBC Connection class and how pooling Connection objects helps to solve a number of common problems. We look at two ways to implement connection-pooling capabilities the JDBC way and by letting a JDBC connection pool simulate a JDBC pool. A connection pool can be made available to the rest of the application -- servlets as well as the JSTL database access actions -- in a number of ways. In this chapter we discuss the approach used in Chapter 18 using an application event listener in more detail as well as an approach that s more flexible but that only works in web containers that support the Java Naming and Directory Interface JNDI . No matter if you use a servlet or a custom action to access the database there are a number of JDBC details that must be handled. To help with this grunt work we look at a generic database access bean that simplifies life and makes the result of a query easy to use. The last section contains an example of an application-specific custom action using this bean. If you need to learn more about JDBC programming than what s covered here I recommend that you look at the JDBC documentation online at http products jdbc or read a book about JDBC such as George Reese s Database Programming with JDBC and Java O Reilly . JDBC Basics The JDBC API is a set of classes and interfaces that allows a Java application to send SQL statements to a database in a vendor-independent way. The API consists mostly of interfaces that define the methods you use in your program. Database engine vendors and third parties provide implementations of these interfaces for
đang nạp các trang xem trước