Compared with the traditional Client/server model database system, the Web database system adopts the three-layer browser/server structure (that is, the network browser/web server/database server structure), which has great advantages. The Web database system gives full play to the DBMS efficient data storage and management capabilities, with B/S mode as the platform, the client unified as a Web browser, to provide users with simple, content-rich database services, has become the Internet and the core services provided by the intranet, Provides technical support for e-business on the Internet. The key technology of Web database system is the connection and access optimization between Web and database.
Web Database Connection technology
Common Web Database Connectivity technologies include CGI technology, WEBAPI Technology, RAD Technology, and JDBC technology. The earliest CGI technology was supported by almost all Web servers, but there were serious flaws such as slow running, poor development and portability. The advent of WEBAPI overcomes the problem of speed, but development is more difficult. The various APIs are incompatible and extremely limited in scope. RAD Technology (rapid development technology) fundamentally changes the status of development difficulties, but it is dependent on a particular Web server and lacks versatility.
The biggest advantage of JDBC (Java database Connectivity) technology is that it provides a standard interface for all database management systems and provides uniform access to a variety of relational databases, which can be grouped into the following three sections:
One of the main features of the JDBC API is simple and easy to master. It consists primarily of interfaces rather than integration classes, and is included in the java.sql and javax.sql two packages. These interfaces are performed by software vendors that provide JDBC drivers.
The purpose of the JDBC Driver Manager is to provide the most basic guideline function on the JDBC operating structure, that is, when a JDBC API program makes a database call, it chooses the correct JDBC driver to connect.
The JDBC-driven role is to actually connect the database and handle it appropriately when the JDBC API makes a data call to the program. JDBC Driver provides the interface class for the JDBC API.
JSP Technology
The characteristics of JSP technology
Java Server page (JSP) is a Web page touch board that dynamically generates HTML documents using Java code. The JSP runs on the server-side component called the JSP container, which transforms the JSP into an equivalent Java Servlet. Because of this, the servlet and JSP pages are ultimately related. JSP pages have all the benefits of a servlet, such as good performance and scalability, embedded support for HTTP sessions, and so on. JSP pages also have their own advantages, such as automatic recompilation and greater compatibility with web development tools, if needed.
The JSP container automatically manages the JSP page based on the timestamp of each file. When a request for a JSP page is issued, the container is first judged with. The name of the class that corresponds to the JSP file.
If the class does not exist or is more than. The old JSP file, and then the container creates Java source code for an equivalent servlet and compiles it. If the servlet instance is not running, the container loads the servlet class and creates an instance. Finally, the container sends a thread to handle the current HTTP request in the loaded instance. So, a JSP page has three kinds of existence form, namely JSP source code, Java source code and compiled Java class.
JSP elements can be divided into three types: pseudo directives, script elements (including expressions, scripts, and declarations), and actions. Where the pseudo directives are commands that instruct the JSP container to generate what code, 9 suppressed objects can be used in expressions and scripts, and the behavior is to create, modify, or use the top-level JSP elements of an object, using strict XML syntax encoding.
using JSP to realize the connection between Web and database
Java uses JDBC technology to process a database is a comprehensive, common way to connect with the database, perform queries and extract data and other operations. Many relational database management systems have JDBC drivers. The specific steps are as follows:
1. Complete the Environment setting, import java.sql package, order as follows:
#import java.sql.*
2. Load Drive
The JDBC specification divides drives into JDBC-ODBC bridges, pure Java to database middleware, and pure Java directly to the database based on the drive structure. Here, using the local API and some Java type drives, explicitly create a drive instance as follows and register with drive Manager:
Drivermanager.registerdriver (New Oracle.jdbc.driver.OracleDriver ());
3. Connecting to a database
The drive manager retains the registered drive list and calls its getconnection () method to get the connection object. The getconnection () parameters are the database server's IP address, port number, library name, and the account and password required to log on to the database, examples are as follows:
Connection conn= dirvermanager.getconnection (
"Jdbc:oracle:thin: @localhost: 1521:demo", "username", "password") ; |
4. Statement interface
The SQL language consists of statements that create, represent, and extract data from a relational database. The object-oriented representations of these SQL statements provided by JDBC encapsulate their text, execution status, and results. This representation is called the Java.sql.Statement interface. The two sub-interfaces that use precompiled SQL PreparedStatement and the callablestatement that invoke the stored procedure extend the functionality of statement, as shown in the following example:
Statement stmt=conn.createstatement ();
5. Get the result set
A result set is a sorted list of table rows, expressed using the Java.sql.ResultSet interface in JDBC. The result set is generated by the ExecuteQuery () method of the statement interface or by some metadata method calls, as follows:
ResultSet rs=stmt.executequery (SQL);
optimize access efficiency with connection pooling
In this example, the application tier uses WebLogic 6.1, the database layer is Oracle8.1.6, and the client uses the Navigate browser.
Instance
In this example, establish a connection pool named ConnectionPool. The basic properties of the ConnectionPool are as follows:
The limit of the number of connections in the M_connectionpoolsize connection pool, the
maximum number of connections in the M_connectionpoolmax connection pool,
and the maximal number of m_connectionusecount of a connection;
m_ ConnectionTimeout The maximum idle time of a connection;
m_maxconnections =-1 max connections at the same time;
M_timer timer. |
These properties define the valid status values of the connection pool and each of these connections.
The self-management of the connection pool is actually done by periodically determining the status of each connection and the number of connections.
Here you can define the basic interfaces that connectionpool need to complete management, specifically:
public class ConnectionPool implements timerlistener{public
Boolean Initialize ()//connection pool initialization public
void destroy ()///Connection pool destroy public
synchronized java.sql.Connection getconnection ()//Fetch a connection public
synchronized void Close ()/ /Close a connection
private synchronized void Removefrompool ()//Remove a connection from the connection pool
private synchronized void Fillpool ()//Maintenance Connection Pool Size public
synchronized void timerevent ()//Timer event handling function
} |
With these interfaces, the basic management of connection pooling can already be completed. The stateful inspection of the connection pool is completed in the Timeevent () function, and the connection pool remains at least the minimum number of connections when Fillpool (). Because the user wants to save the status of each connection, a database connection object is also required to see:
Class connectionobject{public
java.sql.Connection con. Public boolean inUse//is used flag public
long LASTACCE ss Last start use time public
int usecount;//Times used
} |
After adding the Connectionobject object, the ConnectionPool should only be connectionobject, and the other process needs only the Connectionobject con attribute. So here's a second class that gets the interface to the return connection as another process:
CLASS conn{
getconnection ();//Remove a valid connection from the connection pool
closeconnection ();//return connection, the connection is not closed at this time, only the connection pool is put back
Destroypool (); Destroy Connection Pool
} |
At present, using JSP technology to build the B/s structure of the Web database system is a popular way, while the use of database connection pool system in terms of efficiency and stability than the use of other traditional systems of the system is much better. Database connection pool is a feasible solution to the complex problems in the whole system. However, in practical applications, JDBC connection is only a small part of large Web application systems, the database connection pool management program and the Web server, JSP engine and RDBMS engine management strategy are likely to conflict. Users should fully consider the various parts of the system in order to give full play to their efficiency