What is JDBC?

Source: Internet
Author: User
Tags driver manager sybase sybase database

JDBC is a Java API that can be used to execute SQL statements (applicationprogramminginterface application design interface ). It consists of classes and interfaces written in some java languages. JDBC provides a standard application design interface for database application developers and Database Front-End Tool developers, allowing developers to write complete database applications in pure Java language.

 



1. Development History from ODBC to JDBC
Speaking of JDBC, it is easy to think of another very familiar word "ODBC ". Are there any links between them? If so, what is the relationship between them?

ODBC is short for opendatabaseconnectivity. It is a standard application data interface that is used to access data in a related or unrelated Database Management System (DBMS) and implemented in C language. Through odbcapi, applications can access data stored in a variety of different database management systems (DBMS), regardless of the data storage format and programming interface used by each DBMS.

1. ODBC Structure Model
The structure of ODBC includes four main parts: application interface, driver manager, database drive and data source.
Application Interface: shields the differences in function calls between different ODBC database drivers and provides users with a unified SQL programming interface.
Driver MANAGER: load the database drive for the application.
Database drive: Implements ODBC function calls and provides SQL requests to specific data sources. If necessary, the database drive modifies the application request so that the request complies with the grammar supported by the relevant DBMS.
Data source: it consists of the data you want to access, the operating system associated with it, the DBMS, and the network platform used to access the DBMS.
Although the ODBC driver manager mainly aims to load the database drive for ODBC function calling, the database drive itself also executes ODBC function calling and works with the database. Therefore, when the application system makes a call to connect to the data source, the database drive can manage the communication protocol. When a connection is established with the data source, the database drive can process the requests sent from the application system to the DBMS, and perform necessary translation for the analysis or design from the data source, return the result to the application system.

2. The birth of JDBC

Java has become popular around the world since it was officially announced in May 1995. A large number of programs are written in Java, including database applications. Since there is no Java API, programmers have to add c-language ODBC function calls to Java programs. This makes the outstanding features of many Java unable to be fully utilized, such as platform independence and object-oriented features. As more and more programmers are interested in the Java language, more and more companies are investing more and more energy in Java program development, and more requests are required to access database APIs through Java language interfaces. Due to ODBC's shortcomings, such as its inaccessibility and lack of object-oriented features, sun decided to develop an interface for developing database applications whose Java language is an interface. In jdk1.x, JDBC is only an optional component. When jdk1.1 is published, the SQL class package (jdbcapi) becomes a standard component of the Java language.

Ii. JDBC technology Overview

JDBC is a Java API that can be used to execute SQL statements (applicationprogramminginterface, application design interface ). It consists of classes and interfaces written in some java languages. JDBC provides database application developers and Database Front-End Tool developers with a standard application design interface, allowing developers to write complete database applications in pure Java language.

By using JDBC, developers can easily send SQL statements to almost any database. That is to say, developers do not have to write a program to access Sybase, write another program to access Oracle, and write another program to access Microsoft sqlserver. Programs Written in JDBC can automatically send SQL statements to the corresponding database management system (DBMS ). In addition, applications written in Java can run on any platform that supports Java.
Different applications must be written on different platforms. The combination of Java and JDBC enables developers to truly implement "writeonce, runeverywhere!" during database development !" Java is robust, secure, easy to use, and supports automatic online downloads. It is essentially a good programming language for database applications. What it needs is how Java applications connect to a variety of databases. JDBC is the key to achieving this connection.

JDBC extends Java capabilities. For example, you can use Java and jdbcapi to publish a Web page with an applet that can access the remote database. Or enterprises can use JDBC to connect all employees (they can use different operating systems, such as windwos, machkers, and UNIX) to several global databases on the Intranet, these global databases may be different. As more and more developers use the Java language, the demand for the ease of database access by Java is getting stronger and stronger.

MIS administrators like Java and JDBC, because it makes it easier to publish information economically. All kinds of transactions that have been installed in the database will continue to run normally, and even these transactions are stored in different database management systems. For new database applications, the development time will be shortened, and the installation and version upgrade will be greatly simplified. A programmer can write or rewrite a program and place it on the server. Each user can access the server to obtain the latest version. For the information service industry, Java and JDBC provide a good way to update information to external users.


1. JDBC task
To put it simply, JDBC can accomplish the following three tasks:
1) establish a connection to the same database;
2) Send SQL statements to the database;
3) process the results returned by the database.
2. JDBC-an underlying API
JDBC is an underlying API, which means that it will directly call SQL commands. JDBC is fully qualified for this task and easier to implement than other databases. It is also the basis for constructing high-level APIs and database development tools. High-level APIs and database development tools should be user-friendly, easy to use, and easy to understand. However, all such APIs will eventually be translated as underlying APIs such as JDBC. Currently, two JDBC-based high-level APIs are in the development stage.
1) the SQL language is embedded into the Java Preprocessor. Although DBMS has implemented SQL query, JDBC requires that the SQL statement be transmitted 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 numerical values. Then, the SQL Preprocessor translates the mixed Java/SQL programs into Java programs with jdbcapi.
2) implement direct ing from relational databases to Java classes. Javasoft and other companies have announced that they want to implement this technology. In this "Object/relationship" ing, each row of the table will become an instance of this type, and the values in each column correspond to an attribute of the instance. Programmers can directly operate on Java objects, and the SQL calls required for access will be generated internally. You can also implement more complex ing, such as implementing multiple table rows in a Java class. With the increasing interest in JDBC, more and more developers have begun to use JDBC-based tools for development. This makes the development work
Easy. At the same time, programmers are also developing applications that are easier for end users to access the database.

3. Comparison of JDBC, ODBC and other APIs

So far, Microsoft ODBC may be the most widely used API for accessing relational databases. It provides the ability to connect to almost any platform and any database. So why not use ODBC directly from Java?

The answer is that ODBC can be used from Java, but it is best to implement it with the help of JDBC with the JDBC-ODBC bridge. So why does JDBC be required? 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 a local C program from a Java program brings a series of shortcomings similar to security, integrity, and robustness.

2) Secondly, fully accurate ODBC translation from C code ODBC to Java API writing is not satisfactory. For example, Java does not have a pointer, while ODBC uses a pointer in a large amount, including a very error-prone empty Pointer "Void *". Therefore, for Java programmers, it is natural to imagine JDBC as an API that converts ODBC to object-oriented.

3) ODBC is not easy to learn. It blends simple features with complex features, and even has complicated options for very simple queries. JDBC, on the contrary, maintains the simplicity of simple things, but allows complex features.


4) JDBC APIs are required for pure Java solutions. When using ODBC, you must install the ODBC driver and driver manager on each client. If the JDBC driver is fully implemented in Java, the JDBC code can be automatically downloaded and installed to ensure its security. In addition, this will adapt to any Java platform, from Network Computer NC to mainframe.


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


Recently, Microsoft has launched new APIs in addition to ODBC, such as rdo, ADO, and oledb. In fact, these Apis work in the same direction as JDBC in many aspects, that is, they strive to become an object-oriented ODBC-based class interface. However, these interfaces cannot replace ODBC at present, especially when ODBC drivers are fully formed in the market, and more importantly, they are just "beautiful packaging" of ODBC ".

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

JDBC supports two-tier models and three-tier models for database access.
In the two-layer model, a Java appple or ja-va application is directly connected to the database. This requires a JDBC drive that can be connected directly to the accessed database. User SQL statements are sent to the database, and the execution results of these statements are returned to the user. Databases can be connected on the same machine or on another machine over the network. This is called the "Client/Server" structure. The user's computer acts as the client and the computer that runs the database acts as the server. This network is an intranet. For example, the Intranet connecting all employees can also be an Internet.

In a layer-3 model, commands are sent to the "middle layer" of the service, while the "middle layer" sends SQL statements to the database. The database processes SQL statements and returns the results to the "middle layer", and then the "middle layer" returns them to the user. The MIS administrator will find the three-tier model attractive, because the "middle layer" can control access and coordinate database updates, another advantage is that a "middle layer" user can use an easy-to-use high-level API, which can be converted from the "middle layer" to the underlying call. Moreover, in many cases, the layer-3 model can provide better performance.

So far, the "middle layer" is usually implemented using C or C ++ to ensure its high performance. However, with the introduction of the optimization compiler, the byte code of Java is converted into an efficient machine code, and the implementation of the "middle layer" using Java will become more and more practical. JDBC is the key to allowing access to the database from a Java "middle layer.


 


JDBC supplement:


Jdbctm is a javatm API used to execute SQL statements (interestingly, JDBC itself is a trademark name rather than an abbreviation; however, JDBC is often considered to be "Java database connectivity )"). It consists of a group of classes and interfaces written in Java programming language. JDBC provides a standard API for tools/database developers to write database applications using pure Java APIs.

With JDBC, it is easy to send SQL statements to various relational databases. In other words, with JDBC APIs, you do not have to write a program for accessing the Sybase Database, write another program for accessing the Oracle database, and write another program for accessing the Informix database. You only need to use the jdbc api to write a program. It can send SQL statements to the corresponding database. Moreover, applications written in the Java programming language do not have to worry about writing different applications for different platforms. The combination of Java and JDBC enables programmers to run programs on any platform only once.

Java is a powerful, secure, easy to use, easy to understand, and can be automatically downloaded from the network. It is an outstanding language for writing database applications. All you need is the method of dialog between Java applications and different databases. JDBC serves as a mechanism for this purpose.

JDBC extends Java functions. For example, you can use Java and JDBC APIs to publish a webpage containing an applet, and the information used by the applet may come from a remote database. Enterprises can also use JDBC to connect all employees to one or more internal databases over the Intranet (even if these employees use different operating systems such as Windows, Macintosh, and UNIX ). As more and more programmers begin to use the Java programming language, the requirements for convenient access to the database from Java are also increasing.

MIS administrators like the combination of Java and JDBC because it makes information dissemination easy and economical. Enterprises can continue to use their installed databases and easily access information, even if the information is stored on different database management systems. The development period of new programs is very short. Installation and version control will be greatly simplified. A programmer can write an application only once or update it only once, and then put it on the server. then anyone can get the latest version of the application. For commercial sales information services, Java and JDBC can provide external customers with a better way to obtain information updates.

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.