Http://www.35java.com/zhibo/forum.php? MoD = viewthread & tid = 260 & extra = Page % 3d2
JDBC technology is the standard for database programming in Java. With the widespread rise of B/S in recent years, Java technology is increasingly reused on servers. As a key part of the information system, database programming is a must for programmers. The JDBC technology provides some available programming interfaces to process some basic transactions, but we also find that, if you simply use the programming interface provided in the JDBC specification to complete the transaction logic, Code High redundancy and low programming efficiency. Based on this, if, on the basis of the underlying interface, the appropriate design pattern is used for abstract encapsulation, and some specific designs are followed, A Scalable framework is formed on top of the JDBC standard interface. Development at this abstract level will greatly improve both reusability, reliability, and development efficiency. 1. Key points of the design model
The so-called mode is a solution to a specific problem in a specific situation. These solutions are often summed up by experience and are recognized as excellent. The design mode is a well-recognized design solution for specific problems in specific scenarios during the object-oriented software design. The object-oriented thinking has been around for so many years, and now there are a lot of specific models that deserve our reference when we encounter most problems in software design.
2. Key Points of JDBC Programming
The general programming process is as follows:
(1) obtain the database connection.
(2) perform specific SQL statement operations on the obtained connection.
If the above operations are performed on each database access, without some organizational design, the Code redundancy will be very high, Program The workload is also very large, and the code written is not flexible, so it is necessary to introduce a certain design pattern to improve code reusability and scalability.
3. Use the factory method mode to control the generation of database connections
In actual systems that have already been determined, the database is often rarely changed. Therefore, the first step to getting the database is the same for almost all accesses. In order to improve the reusability, it is necessary to extract it into a separate module. Here, only the factory method can be used to encapsulate the database connection operation. Considering the frequent connection, there is no need to request a connection to the database every time you access the database. We can use the connection pool technology to manage a certain number of database connections. Here we define a connectionpool class, the database connection operation is defined as newconnection ().
The following is the basic code snippet of the factory method:
Public
class connectionpool ......
private connection newconnection () {
......
connection con = drivermanager. getconnection (URL, user, password);
......
return con;
}