This introduction is taken from JDBCTMDatabaseAccessfromJavaTM: ATutorialandAnnotatedReference. JavaSoft is currently preparing this book. This is a tutorial and an important reference manual for JDBC. it will be part of the Java series and published by Addison-Wesley Publishing Company JDBCJDBCTM in the spring of 1997.
This document is excerpted from JDBCTM Database Access from JavaTM: A Tutorial and Annotated Reference.
JavaSoft is currently preparing this book. This is a tutorial and an important reference manual for JDBC, which will be published by Addison-Wesley in the spring of 1997 as part of the Java series.
1.1 What is JDBCTM?
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 the jdbc api, 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 the computers used by these employees
Windows, Macintosh, UNIX, and other operating systems ). 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.
1.1.1 What is the purpose of JDBC?
To put it simply, JDBC can do three things:
Establish a connection with the database,
Send SQL statements,
Processing result.
The following code snippet provides a basic example of the preceding three steps:
Connection con = DriverManager. getConnection (
"Jdbc: odbc: wombat", "login", "password ");
Statement stmt = con. createStatement ();
ResultSet rs = stmt.exe cuteQuery ("SELECT a, B, c FROM Table1 ");
While (rs. next ()){
Int x = rs. getInt ("");
String s = rs. getString ("B ");
Float f = rs. getFloat ("c ");
}
1.1.2 JDBC is a low-level API and is the foundation of advanced APIs
JDBC is a "low-level" interface, that is, it is used to directly call SQL commands. In this regard, it provides excellent functionality and is easier to use than other database connection APIs, but it is also designed as a basic interface on which advanced interfaces and tools can be created. An advanced interface is a user-friendly interface. it uses an API that is easier to understand and more convenient. This API is converted to a low-level interface such as JDBC behind the scenes. At the time of writing this article, two JDBC-based advanced APIs are being developed: