Overview of the JDBC Basics tutorial

Source: Internet
Author: User

1.1 What is JDBCTM?

JDBCTM is a JAVATM API for executing SQL statements (interestingly, JDBC itself is a trademark name rather than an abbreviation; however, JDBC is often considered to represent "Java database connection (Java DB Connectivity)"). It consists of a set of classes and interfaces written in the Java programming language. JDBC provides tools/database developers with a standard API that enables them to write database applications with a pure Java API.

With JDBC, it's easy to send SQL statements to various relational databases. In other words, with the JDBC API, there is no need to write a program specifically to access the Sybase database, write a program for accessing an Oracle database, write another program for accessing the Informix database, and so on. Suffice it to write a program with the JDBC API to send SQL statements to the appropriate database. Also, applications written in the Java programming language do not need to worry about writing different applications for different platforms. Combining Java with JDBC will allow programmers to write the program once and let it run on any platform.

Java is robust, secure, easy-to-use, easy to understand, and automatically downloadable from the Web, and is an excellent language for writing database applications. All you need is a way for the Java application to talk to a variety of different databases. And JDBC is the mechanism for this purpose.

JDBC extends the functionality of Java. For example, a Web page containing applets can be published with the Java and JDBC APIs, and the information used by the applet may be from a remote database. Enterprises can also use JDBC to connect all employees to one or more internal databases through an intranet (even if they use computers with various operating systems such as Windows, Macintosh, and UNIX). As more and more programmers begin to use the Java programming language, the need for easy access to the database from Java is increasing.

MIS administrators like the combination of Java and JDBC because it makes it easy and economical to spread information. Organizations can continue to use their installed databases and access information easily, even if they are stored on different database management systems. The new program has a very short development period. Installation and versioning will be greatly simplified. Programmers can write only one application or update it once, and then put it on the server, and then anyone can get the latest version of the application. For business sales information Services, Java and JDBC can provide external customers with a better way to get information updated.

What is the purpose of 1.1.1 JDBC?

Simply put, JDBC can do three things:

Establish a connection with the database,

Send SQL statement,

Process the results.

The following code snippet gives a basic example of the above three steps:

Connection con = DriverManager.getConnection ("jdbc:odbc:wombat", "login", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next())
System.out.println(rs.getString("a") + " " + rs.getString("b") + " " + rs.getString("c"));

1.1.2 JDBC is a low-level API that is the foundation of advanced APIs

JDBC is a "low-level" interface, which means it is used to invoke SQL commands directly. It is very functional in this regard and is easier to use than other database connection APIs, but it is also designed as an infrastructure interface on which to build advanced interfaces and tools.

The advanced interface is the "user-friendly" interface, which uses an API that is easier to understand and easier to convert behind the scenes into low-level interfaces such as JDBC. At the time of writing this article, two advanced JDBC based APIs are being developed:

An embedded SQL used in Java. At least one provider is planning to write it. DBMS implementation sql: A language specifically designed to be used in conjunction with a database. JDBC requires that the SQL statement be passed to the Java method as a String. Instead, the embedded SQL preprocessor allows programmers to mix SQL statements directly with Java. For example, you can use Java variables in SQL statements to accept or provide SQL values. The embedded SQL preprocessor then converts this java/sql mixture to Java through a JDBC call. A direct mapping of relational database tables to Java classes. JavaSoft and other providers are claiming to implement the API. In this "object/relationship" mapping, each row in the table corresponds to an instance of the class, and the value of each column corresponds to one of the properties of the instance. As a result, programmers can manipulate Java objects directly, and the SQL calls required to access data are automatically generated under cover. You can also provide more complex mappings, such as combining rows from multiple tables into a Java class.

As people become increasingly interested in JDBC, more and more developers have been using JDBC based tools to make programs easier to write. Programmers have also been writing applications that attempt to make access to the database easier for end users. For example, an application can provide a menu that selects database Tasks. When a task is selected, the application gives hints and blanks to fill in the information needed to perform the selected task. When the required information is entered, the application will automatically invoke the required SQL command. With the help of such a program, a database task can be performed even if the user does not know the syntax of SQL at all.

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.