JDBCTM Guide: Entry 2

Source: Internet
Author: User
Content: 2 JDBCJDBCTM

Content: 2-connection this overview is from JDBCTM Database Access from JavaTM: A Tutorial
And Annotated Reference. JavaSoft is currently preparing this book. This book is a tutorial and an important reference manual for JDBC. it will be published by Addison-Wesley in the spring of 1997 as part of the Java series.
2.1 Overview
The Connection object represents the Connection to the database. The connection process includes the executed SQL statement and the result returned by the connection. An application can have one or more connections to a single database, or many databases.
2.1.1 The standard method for establishing a connection to a database is to call DriverManager. getConnection.
Method. This method accepts strings containing a URL. The DriverManager class (the so-called JDBC management layer) will try to find the driver that can be connected to the database represented by that URL. The DriverManager class contains a list of registered Driver classes. When the getConnection method is called, it checks every driver in the list until it finds the driver that can be connected to the database specified in the URL. The Driver method connect uses this URL to establish the actual connection.

You can bypass the JDBC management layer to directly call the Driver method. This can be useful in the following special circumstances: when two drives can be connected to the database at the same time, the user needs to explicitly select the specific drive. But in general, it is easier to let the DriverManager class handle the process of opening a connection.
The following code opens a connection to a database in the URL "jdbc: odbc: wombat. The user ID is "oboy" and the password is "12 Java ":
String url = "jdbc: odbc: wombat ";
Connection con = DriverManager. getConnection (url, "oboy", "12 Java ");
2.1.2 URLs in general usage are often confused due to URLs. we will first briefly describe general URLs and then discuss JDBC URLs.
URL (unified resource locator) provides the information needed to locate resources on the Internet. You can think of it as an address.
The first part of the URL specifies the protocol used to access information, followed by a colon. Common protocols include ftp and http ").
If the protocol is "file", the resource is on a local file system rather than on the Internet (the following example is used to indicate the part we described; it is not a part of the URL ).
Ftp://javasoft.com/docs/JDK-1_apidocs.zip
Http://java.sun.com/products/jdk/CurrentRelease
File:/home/haroldw/docs/books/tutorial/summary.html
The rest of the URL (after the colon) provides information about the location of the data resource. If the protocol is file, the rest of the URL is the file path. For the ftp and http protocols, the rest of the URL identifies the host and can provide a more detailed address path. For example, the following is the URL of the external oft homepage. This URL only identifies the host:
Http://java.sun.com from the home page, you can go to many other pages, one of which is
JDBC homepage. The URL of the JDBC home page is more specific and looks like: http://java.sun.com/products/jdbc
2.1.3 jdbc url provides a method to identify a database so that the corresponding driver can identify the database and establish a connection with it. In fact, the driver programmer will decide what jdbc url to use to identify a specific driver. Users do not have to worry about how to form JDBC URLs; they only need to use the urls provided with the driver used. The role of JDBC is to provide certain conventions that drivers programmers should follow when constructing their JDBC URLs.
Since JDBC URLs must be used together with various drivers, these conventions should be flexible. First, they should allow different drivers to use different schemes to name databases. For example, the odbc sub-protocol allows (but is not required) URLs to contain attribute values. Second, the jdbc url should allow the driver programmer to include all required information. In this way, you can enable the database connection of the applet that you want to talk to a given database without requiring you to perform any system management work.

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.