Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand JDBC technology

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to understand JDBC technology". In daily operation, I believe many people have doubts about how to understand JDBC technology. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to understand JDBC technology". Next, please follow the editor to study!

JDBC is a JavaAPI (ApplicationProgrammingInterface application programming interface) that can be used to execute SQL statements. It consists of classes and interfaces written in the Java language. JDBC provides a standard application design interface for database application developers and database foreground tool developers, so that developers can write complete database applications in pure Java language.

I. the development process from ODBC to JDBC

When it comes to JDBC, it is easy to think of another very familiar word "ODBC". Is there a connection between them? If so, what is the relationship between them?

ODBC is the abbreviation of OpenDatabaseConnectivity. It is a standard application program data interface that is used to access data in related or unrelated database management systems (DBMS) and is implemented in C language. With ODBCAPI, applications can access data stored in many different database management systems (DBMS), regardless of the data storage format and programming interface used by each DBMS.

The structural model of 1.ODBC

The structure of ODBC consists of four main parts: application program interface, driver manager, database driver and data source.

◆ API: shields the difference of function calls between different ODBC database drivers and provides users with a unified SQL programming interface.

◆ Drive Manager: loads the database drive for the application.

◆ database driver: a function call that implements ODBC and provides SQL requests to specific data sources. If necessary, the database driver modifies the application's request so that it conforms to the grammar supported by the relevant DBMS.

◆ data source: consists of the data that the user wants to access and the operating system associated with it, DBMS, and the network platform used to access DBMS.

Although the main purpose of the ODBC drive manager is to load the database drive for ODBC function calls, the database driver itself also performs ODBC function calls and cooperates with the database. Therefore, when the application system makes a call to connect with the data source, the database driver can manage the communication protocol. When the connection with the data source is established, the database driver can process the requests sent by the application system to the DBMS, translate the analysis or the design sent from the data source, and return the results to the application system.

The birth of 2.JDBC

Since the Java language was officially released in May 1995, Java has become popular all over the world. There are a large number of programs written in java, including database applications. Because there is no API in Java language, programmers have to add C language ODBC function calls to Java programs. This makes many excellent features of Java can not be brought into full play, such as platform independence, object-oriented features and so on. As more and more programmers like Java language day by day, more and more companies devote more and more energy to Java program development, and the demand for java language interface to access database API is becoming stronger and stronger. Also because of the shortcomings of ODBC, such as it is not easy to use, no object-oriented features and so on, SUN decided to develop a database application development interface with Java language as interface. In the JDK1.x version, JDBC is only an optional part, and by the time JDK1.1 is released, the SQL class package (that is, JDBCAPI) has become a standard part of the Java language.

II. Overview of JDBC technology

JDBC is a JavaAPI (ApplicationProgrammingInterface, application programming interface) that can be used to execute SQL statements. It consists of some classes and interfaces written in Java language. JDBC provides a standard application design interface for database application developers and database foreground tool developers, so that developers can write complete database applications in pure Java language.

By using JDBC, developers can easily pass SQL statements to almost any database. In other words, developers don't have to write one program to access Sybase, another program to access Oracle, and another program to access Microsoft's SQLServer. Programs written in JDBC can automatically transmit SQL statements to the corresponding database management system (DBMS). Not only that, applications written in Java can run on any platform that supports Java, without having to write different applications on different platforms. The combination of Java and JDBC allows developers to realize "WriteOnce,RunEverywhere!" when developing database applications.

Java is robust, secure, easy to use, and supports automatic download on the Internet. In essence, it is a good programming language for database applications. What it needs is how to connect Java applications to a variety of databases, and JDBC is the key to this connection.

JDBC extends the capabilities of Java, such as using Java and JDBCAPI to publish a Web page with Ap?plet that can access a remote database. Or companies can use JDBC to connect all their employees (who can use different operating systems, such as Windwos,Machintosh and UNIX) to several global databases on In?tranet, which can be different. As more and more program developers use the Java language, the demand for easy operation of Java access to the database becomes stronger and stronger.

MIS managers like Java and JDBC because it makes it easier and more economical to publish information. All kinds of transactions already installed in the database will continue to operate normally, even if they are stored in different database management systems; for new database applications, the development time will be shortened, installation and version upgrades will be greatly simplified. Programmers can write or rewrite a program and put it on the server, and each user can access the server to get a version. For the information service industry, Java and JDBC provide a good way to update information to outside users.

The task of 1.JDBC

In a nutshell, JDBC can accomplish three things:

◆ establish a connection with the same database

◆ sends SQL statements to the database

◆ processes the results returned by the database.

2.JDBC is a low-level API

JDBC is an underlying API, which means it invokes the SQL command directly. JDBC is fully qualified for this task and is easier to implement than other database interconnections. It is also the basis for constructing high-level API and database development tools. High-level API and database development tools should be more user-friendly, easier to use, and easier to understand. But all such API will eventually be translated into an underlying API like JDBC. At present, two high-level API based on JDBC are in the development stage.

1) the SQL language is embedded in the preprocessor of Java. Although DBMS has implemented SQL queries, JDBC requires the SQL statement to be passed to the Java program as a string parameter. The embedded SQL preprocessor allows programmers to mix SQL statements: Java variables can be used in SQL statements to receive or provide values. The preprocessor of SQL will then translate this Java/SQL mixed program into a Java program with JDBCAPI.

2) realize the direct mapping from relational database to Java class. Javasoft and other companies have announced plans to implement this technology. In this "object / relational" mapping, each row of the table becomes an instance of this type, and the value of each column corresponds to an attribute of the instance. Programmers can directly manipulate Java objects; the SQL calls required for access will be generated directly internally. You can also implement more complex mappings, such as rows of multiple tables in a Java class.

With the growing interest in JDBC, more and more developers have begun to use JDBC-based tools for development. This makes the development work easier. At the same time, programmers are developing applications that make it easier for end users to access databases.

Comparison between 3.JDBC and ODBC and other API

By far, Microsoft's ODBC is probably the most widely used API for accessing relational databases. It provides the ability to connect to almost any platform, any kind of database. So why not use ODBC directly from Java?

The answer is that you can use ODBC from Java, but * is implemented with JDBC-ODBC bridge with the assistance of JDBC. So why do you need JDBC? To answer this question, there are several aspects:

1) ODBC is not suitable for direct use in Java. ODBC is an API implemented in C language. Calling local C programs from Java programs will bring a series of similar disadvantages such as security, integrity and robustness.

2) secondly, it is not satisfactory to achieve completely accurate translation from C code ODBC to ODBC written by JavaAPI. For example, Java does not have pointers, while pointers are heavily used in ODBC, including the error-prone null pointer "void*". Therefore, it is natural for Java programmers to think of JDBC as transforming ODBC into an object-oriented API.

3) ODBC is not easy to learn, it mixes simple features with complex features, and has complex options for even very simple queries. JDBC, by contrast, maintains the simplicity of simple things, but allows for complex features.

4) JavaAPI such as JDBC is necessary for pure Java solutions. When using ODBC, people must install the ODBC driver and driver manager on each client. If the JDBC driver is implemented entirely in the Java language, then the JDBC code can be downloaded and installed automatically and securely, and this will be suitable for any Java platform, from network computer NC to mainframe Mainframe.

All in all, JDBCAPI is the most direct Java interface that embodies the most basic abstract concepts of SQL. It is built on ODBC, so programmers familiar with ODBC will find it easy to learn JDBC. JDBC maintains the basic design features of ODBC. In fact, both interfaces are X/OPENSQL-based call-level interfaces (CLI). The difference between them is that JDBC is based on the style and advantages of Java and strengthens the style and advantages of Java.

Recently, Microsoft introduced new API in addition to ODBC, such as RDO,ADO and OLEDB. These API are actually working in the same direction as JDBC in many ways, that is, trying to become an object-oriented, ODBC-based class interface. However, these interfaces are not a substitute for ODBC at present, especially when ODBC drives are fully formed in the market, and more importantly, they are just "beautiful packaging" for ODBC.

4.JDBC two-tier model and three-tier model

JDBC supports a two-tier model and a three-tier model to access the database. In the two-tier model, a java Appple or a JA-va application connects directly to the database. This requires a JDBC drive that can be connected to a database that can be accessed directly. The user's SQL statements are passed to the database, and the results of the execution of these statements are passed back to the user. The database can be connected on the same machine or on another machine through the network. This is called the "Client/Server" structure, with the user's computer as the Client and the computer running the database as the Server. This network can be an intranet, such as an intranet that connects all employees, or, of course, internet.

In the three-tier model, commands are sent to the "middle tier" of the service, and the "middle tier" sends SQL statements to the database. The database processes the SQL statements and returns the results to the "middle tier", which then returns them to the user. MIS administrators will find the three-tier model attractive because the "middle tier" can control access and cooperate with database updates. Another advantage is that if there is a "middle tier" users can use an easy-to-use high-level API, this API can be transformed from the "middle tier" to the underlying call. Moreover, in many cases, the three-tier model can provide better performance.

So far, the "middle tier" is usually implemented in C or C++ to ensure its high performance. However, with the introduction of optimization compiler, it will be more and more practical to convert java bytecode into efficient machine code and use java to realize "middle layer". JDBC is the key to allowing access to the database from a Java "middle tier".

At this point, the study on "how to understand JDBC technology" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report