JDBC is a JavaAPi (ApplicationProgrammingInterface application interface) that can perform SQL statements. It by some Java
The class and interface written in the language. JDBC provides database application developers, and database front desk tool developers provide a standard application design interface.
Make developers to write a complete database application with pure Java language.
First, the development of ODBC to JDBC
Speaking of JDBC, it is easy to think about another familiar word "ODBC". Is there any connection between them? If so, then there is another
What is the relationship?
ODBC is an English-English submissive of OpenDatabaseConnectivity. It is a data used to include data in a related or unrelated database management system (DBMS)
, With C language, standard application data interface. With ODBCAPI, the application can access saved in a variety of different database management systems (DBMS)
The data is in, regardless of how the DBMS uses the data storage format and programming interface.
1. ODBC structure model
The structure of ODBC includes four main parts: application interface, drive manager, database drive, and data source.
Application Interface: The difference between the function call between the masked ODBC database driver provides a unified SQL programming interface for users.
Drive Manager: Load the database driver for the application.
Database driver: Implement ODBC function calls, providing SQL requests for a particular data source. If necessary, the database drive will modify the application.
Ask, make the information that meets the relevant DBMS supported.
Data Source: The data you want to access and consist of the operating system, DBMS, and network platforms used to access DBMS.
Although the main purpose of the ODBC Drive Manager is to load the database driver so that the ODBC function is called, but the database drive itself also performs an ODBC function.
Call and cooperate with the database. Therefore, when the application system issues a call to the data source, the database driver can manage the communication protocol. Be established
When the data source is connected, the database driver can handle the request to DBMS to DBMS, the necessary translation of the design, or from the data source, and will
The result is returned to the application system.
2. JDBC birth
Since Java Language officially announced in May 1995, Java has been popular among the world. A large number of programs written in Java language include databases
Use the program. Since there is no Java language API, the programmer has to add an ODBC function call to the C language in the Java program. This makes a lot of Java's excellence
Features cannot be given to, such as platform-independent, object-oriented characteristics, etc. As more and more programmers have become increasingly loved by Java languages, more and more public
The effort in the development of Java program is increasing, and the API of the Access Database of the Java Language Interface is getting stronger. Also because ODBC has its lack of foot
Where, if it is not easy to use, there is no object-oriented feature, etc., Sun determines the development of a Java language to develop interfaces for interfaces.
In JDK1. In the X version, JDBC is just an optional part. When JDK1.1 is released, the SQL class (JDBCAPI) is the standard department of Java language.
Part.
Second, JDBC Technology Overview
JDBC is a JavaAPi (ApplicationProgrammingInterface, application design interface) that can be used to perform SQL statements. It is
Java language written, interface consisting. JDBC gives database application developers, database front desk tool developers provide standard application design
The mouth allows developers to write complete database applications with pure Java language. By using JDBC, developers can easily transmit SQL statements to almost any database. In other words, developers can write one
The program accesses Sybase, write another program to access Oracle, and write a program to access Microsoft's SQLServer. Programs written by JDBC can automatically use SQL
The statement is transmitted to the corresponding database management system (DBMS). Not only that, the app written in Java can run on any platform that supports Java, not
Different applications must be prepared on different platforms. The combination of Java and JDBC allows developers to truly implement "Writeonce," when developing database applications.
Runeverywhere! "
Java has robust, safe, easy-to-use features, and supports automatic online downloads, essentially a good database application programming language. It needs
The Java application is connected to a wide variety of databases, and JDBC is the key to implementing this connection.
JDBC extends Java's ability. If you use Java and JDBCAPI, you can publish a web page, with a page with an APPLET that accesses the remote database. or
Enterprises can connect all of the employees through JDBC (they can use different operating systems, such as Windwos, Machintosh and Unix) on the intranet
Several global databases, and these global databases can be different. Access data for Java as more and more program developers use Java language
The demand for liberal operability is getting stronger.
MIS managers like Java and JDBC because it can be easily announced easily. Various transactions that have been installed in the database will continue
Normal operation, even these transaction processing is stored in different database management systems; and the development time will be shortened, installed and version for new database applications.
This upgrade will greatly simplify. The programmer can write or override a program, then put it on the server, and each user can access the server to get the latest.
version. For the information service industry, Java and JDBC provide a good way to update information to the outside user.
1. JDBC task
Simply put, JDBC can complete the following three things:
1) Establish a connection in the same database;
2) Send a SQL statement to the database;
3) Handling the result of the database returned.
2. JDBC-a bottom layer API
JDBC is a bottom API, which means it will call the SQL command directly. JDBC is completely qualified for this task, and more easily than other databases.
Now. At the same time, it is also the basis for constructing high-level API and database development tools. High-level APIs and database development tools should be more friendly and more user interfaces.
It is easier to understand. But all such APIs will eventually be translated into a bottom API like JDBC. At present, the two JDBC-based high-rise API is in development.
segment.
1) The SQL language is embedded in Java's preprocessor. Although the DBMS has implemented SQL queries, JDBC requires SQL statements to be transmitted to Java as a string parameter.
sequence. The embedded SQL preprocessor allows programmers to mix SQL statements: Java variables can be used in SQL statements to receive or provide a value. Then SQL's pre-
The processor will translate this Java / SQL mixed program into Java programs with JDBCAPI.
2) Implement direct mapping from the relational database to the Java class. JavaSoft and other companies have announced this technology. In this "object / relationship"
In the mapping, each line of the table will turn into an instance of such a class, each of the values of each column corresponding to an instance of an instance. Programmers can directly operate Java objects; and the SQL call required to access will be directly generated inside. It is also possible to achieve more complex mapping, such as multi-table rows implement in a Java class.
As you are constantly being strong for JDBC interest, more and more developers have begun to develop with JDBC-based tools. This makes development work
easy. At the same time, programmers are also developing applications that have access to databases for end users easier.
3. Comparison of JDBC and ODBC and other APIs
So far, Microsoft's ODBC may be the API of the most widely accessible access database. It provides almost any platform, any number
According to the capacity of the library. So why not directly use ODBC directly from Java?
The answer is that ODBC can be used from Java, but it is best to implement it with JDBC-ODBC bridge with the assistance of JDBC. So why do you need JDBC? take back
Answer this question, there are such aspects:
1) ODBC is not suitable for use directly in Java. ODBC is an API implemented by a C language that causes a series of similar security from the Java program.
The disadvantage of fullness, integrity, and robustness.
2) Second, translation of ODBC written from C code ODBC to Javaapi is not satisfactory. For example, Java does not have a pointer, and ODBC
A pointer is used in a large number of empty pointers "VOID *". Therefore, for Java programmers, JDBC is envisaged into object-oriented objects.
The API is very natural.
3) ODBC is not easy to learn, it is mixed with simple features and complex characteristics, even with a very simple query has complex options. JDBC just
Instead, it maintains the simplicity of simple things, but the complex feature is allowed.
4) JavaApi such as JDBC is necessary for pure Java schemes. When using ODBC, people must install ODBC drives on each client and
Drive Manager. If the JDBC drive is implemented in a Java language, then the JDBC code can automatically download and install, and ensure its security,
Moreover, this will adapt to any Java platform, from the network computer NC to large host mainframe.
All in all, JDBCAPI is the most direct Java interface that can reflect SQL's most basic abstract concept. It constructs on the foundation of ODBC, so familiar with ODBC
Programmers will find that learning JDBC is very easy. JDBC maintains the basic design characteristics of ODBC. In fact, both interfaces are based on X / OpenSQL call levels.
Port (CLI). Their maximum difference is that JDBC is based on Java-based style and advantages, and enhances Java's style and advantages.
Recently, Microsoft introduced new APIs other than ODBC, such as RDO, ADO, and OLEDB. These APIs actually in the same way as JDBC in many ways.
The same direction efforts, that is, efforts become an object-oriented, ODBC-based interface. However, these interfaces do not replace ODBC, especially in ODBC
When the drive is completely formed in the market, it is more important that they are just ODBC's "beautiful packaging".
4. JDBC two-layer model and three-layer model
JDBC supports two layers models, also supports three-layer model access database.
As shown in Figure 3, in the two-layer model, a Java Apple or a JA-VA application is directly connected to the database. This requires the database that can be directly accessed
A JDBC driver for connection. The user's SQL statement is transmitted to the database, and the results executed by these statements will be transmitted back to the user. The database can be connected to the same machine or on another machine. This is called the "client / server" structure, the user's computer is a CLIENT, running the database
The computer is served as a server. This network can be intranet, such as an internal network that connects to all employees, of course, can also be an Internet.
As shown in FIG. 4, in the three-layer model, the command will be sent to the "intermediate layer" of the service, and the "intermediate layer" sends the SQL statement to the database. Database processing
SQL statement and return the result "intermediate layer", then "intermediate layer" returns them to users. MIS administrator will discover three-layer model is very attractive, because "middle
Layer "can perform control of access and collaborate with the database, and another advantage is if there is a" intermediate layer "user to use an easy-to-use high-level
API, this API can be converted by the "intermediate layer" and converted to the underlying call. Moreover, in many cases, the three-layer model can provide better performance.
So far, "intermediate layer" is usually implemented with C or C to ensure its high performance. But with the introduction of the optimization compiler, the Java bytecode conversion
Being an efficient machine code, use Java to achieve the "intermediate layer" will become more and more actual. JDBC is the key to accessing the database from a Java intermediate layer.