Introduction to JDBC Technology

Source: Internet
Author: User
Tags abstract define definition connect odbc query range require

1. Introduction to Java

Many developers and users are looking for convenient ways to access the database in the Java order. Because it is download a robust, safe, easy-to-use, easy to understand and can be automated from the network, c it becomes a good language base for developing database applications. It provides many of the benefits of Java, c+smalltalk+, BASIC, COBOL, and 4GLs. Many companies have started to work with the DBMS connection. Java

Many of the DBMS developers want to be able to write separate DBMS programs, and we believe that a separate DBMS interface will make it the most convenient and rapid development with a wide variety of SQL connections. So we think that the definition of a generic number of Java according to the inventory framework, in a variety of database connectivity modules to provide a unified interface is very meaningful. This allows programmers to face a single database interface, making it possible for database-independent SQL tools and products, so that database-connected developers can provide a wide range of connectivity scenarios. We see the urgent task of defining a generic low-level to support the basic Javadatabase connectivity (JDBC) API. SQL API

Luckily we don't have to design one from the beginning. X we can build our work on the/open SQL CLI (the Microsoft Call-layer interface) (it is also the basis of ' s ODBC). Java

Our main task is to define a natural X-ray connection to the basic abstraction layer and concept defined in the/open CLI. JDBC API

It is important to have ISVs to database developers, to connect developers, to ODBC, and to support application developers. We believe that our work based on the JDBC image layer will be more ODBC and easier to accept. And technically, is a good foundation for our design work. Odbc

Because it is c a language ODBC interface, so in Java Java Direct use is not appropriate. From c to invoke Java code in the security, robustness, ease of implementation, portability and so on have a lot of inconvenience. It makes many of the advantages in these areas not to be played. Odbc

We have implemented an API built in the short term. In the long run, we can provide implementation in other ways. 1.1.

Note JDBC

We are very grateful to many early workers in the field of database, database connection and database Tools. They provided good ideas and suggestions for the early drafts. Their work has played an inestimable role in this norm.

2.

Goals and Philosophy API

This section describes the goals and philosophies that guide this development. 2.1. Sql

Level API Java

Our main goal is to call-level a "call-level" () SQL to the SQL port. means that our primary focus is on executing the literal language API sentences and retrieving the results. We anticipate that the high-level will also be defined and that these may be built on the grassroots interface. Java

These high-level interfaces include the direct and transparent mapping of data in a table to class Java, the use of syntax trees to represent more general queries, and the syntax of SQL embedded inside. Api

We hope that a lot of application development tools will be used by us. API However we also want programmers to be able to use our Java, especially in situations where there is no other means (should be to say database access). 2.2.

SQL-compliant SQL

The database system supports a wide variety of language SQL and semantics, and they are inconsistent with each other in higher-level functions such as external connections, inline processes, and so on, although we can expect these parts to be standardized over time. At the same time we take this attitude and stand: in fact

, an application query need not even is SQL, or it may is a specialized derivative of SQL, e.g. for document or image Quer IES, designed for specific DBMSs. In order to pass JDBC compliance tests and to be called

"JDBC compliant" we require that a driver support at least ANSI SQL-2 level. This is gives applications that want wide portability a guaranteed least the common. We believe ANSI SQL-2 Entry is reasonably powerful and are reasonably widely supported today. * JDBC

Allow SQL Xu query expression directly to the underlying data-driven, such a program can get as much work as the DBMS can, but may be rejected SQL Absolute. In fact, a program's query may not even be SQL, or it's a special evolution, for example: text or graphic queries designed for specialized databases. *

For JDBC, through concurrent JDBC test, and being able to be called ANSI SQL-2, we require a driver at least supported this gives applications that want wide portability a guaranteed least Common denominator standard. This makes it possible for programs that require extensive portability to obtain a minimum denominator (the original text of this sentence is:) ANSI SQL-2. We believe that it is strong enough and that it is adequately supported. 2.3. Jdbc

You must be able to build on the existing database interface JDBC SQL API

We must be able to ensure that the SQL API is sufficient to build on ordinary ODBC, especially. Out parameter these requirements have had an impact on some parts of the specification, particularly the processing of outgoing parameters () and large chunks of data. 2.4.

Must Java ensure that this interface is consistent with other parts of the system Java

The current positive response to Java has been very enthusiastic. This is largely due to the language standards and standard run-time libraries that are considered consistent, simple, and powerful. We will do our best to provide this number of Java library interfaces, which will build on the existing style of the kernel and will further strengthen it. 2.5.

Keep it simple We would prefer to keep the this base API as simplicity as possible

, at least initially. In the general we would prefer to provide a single mechanism for performing a particular task, and avoid provid-ing mechanisms. We'll extend the API later if any important functionality is miss-ing. Api

We will strive to make the basic API volume simple, at least at the beginning. In general, we want to provide only one scenario for implementing each specific task and avoid providing multiple scenarios. If some important features are missing, we will expand this later. 2.6.

Try to maintain a strong, static type JDBC API

We want this to remain as strong as possible type checking, so that as many types of information as possible can be statically expressed. So that as many errors as possible can be found at compile time. Sql

Because this select body is dynamic type, we may encounter a problem where the type does not match when the program is running. For example: When a programmer returns an integer in return for Foo, the actual return is a string "". But we still hope that programmers will be able to express their desired type at compile time so that we can do as many static checks as possible. We also want to be able to support the dynamic type interface when necessary (see chap. Fourth) 2. 7.

Make common tasks simpler

We hope that ordinary tasks can be simple, but not normal work is feasible. Sql

A common task is when a programmer executes a simple select sentence (for example: Insert,update,delete) Select with no arguments, and then (for example) in parameter processes the returned tuple with a simple type. A statement with the incoming parameter () SQL is also common. INOUT

A less common but also very important scenario is when a programmer uses a language SQL sentence that has an out parameter SQL number. We also need to support statements that read and write several megabytes of objects, and more specifically, a statement that returns multiple result sets. Meatdata

We want metadata () to be used very little, just the problem that skilled programmers and development tools need to deal with. Meta-data access functions and dynamic type data access functions at the end of this document, the general programmer may not care about these chapters. 2.8.

Do not approach the same function so that different methods (functions) to achieve (the "method" of the original text is:, VB translation is the following)

An interface design style is the use of very few processes that provide many control flags that are passed as parameters so that they can be used to influence a wide range of behaviors. To express a different function. This tends to work with a lot of methods, but each method is more agreeable to understanding. Java

In general, the internal method kernel class uses different methods () JDBC. The main advantage of this step is that programmers who start learning the basic interface don't have to be bothered by the parameters associated with complex functions. We try to use the same strategy on the interface. In general, different methods are used instead of different logos and multi-purpose methods. 3.

Interface Overview JDBC API

The interface is divided into two levels, one for the developer of the program. The JDBC Driver API is also the underlying one. 3.1. JDBC API

JDBC API

Described by Java as the abstract of the Yi-SQL port, the same application can open a connection to a database, execute statements and process the results. The most important interface is: * Java.sql.DriverManager

Handles driven dial-in and provides support for generating new database connections. * Java.sql.Connection

Represents a connection to a specific database. * Java.sql.Statement

SQL represents a specific container that executes statements against a particular database. * Java.sql.ResultSet

Controls access to the row data for a particular statement. Java.sql.Statement

There are two subtypes: 1. Java.sql.PreparedStatement

SQL is used to perform precompiled statements. 2. Java.sql.CallableStatement

Used to perform a call to a database inline procedure. Jdbc

The following sections provide more descriptions of how 13 works, and the entire definition is shown in Chapter 15. In addition, chapter describes the system if the metadata information of the database is obtained. 3.2. JDBC Driver API

Java.sql.Driver

In Chapter 9, there is a complete definition of the large JDBC partial flooding JDBC API that can only be done by completing these driver defined abstract classes. In particular, all java.sql.Connection must be supplied to, java.sql. State-ment, Java.sql.prepared-statement, and Java.sql.ResultSet DBMS implementations. If the target is out for an inline process with a parameter java.sql.CallableStatement number, then the interface must also be provided. Every database driver Java.sql.Driver must provide a class: Java.sql.DriverManager allows the system to be managed. Driver

An apparently ODBC implementation of ODBC on JDBC provides a bridge to the Jdbc-odbc port. As shown in the previous figure, the JDBC Yufang ODBC is followed by a simple and efficient implementation. Odbc

Another useful driver is to direct contact with database-independent network protocols. Publish a protocol that allows multiple servers to implement methods, such as on or DBMS-specific (although there are already some products that use fixed protocols, we do not intend to standardize them.) ), is desirable.

4. JDBC

Use occasion before looking at specifics of the JDBC API

, a understanding of typical use scenarios is help-ful. There are two common scenarios that must is treated for our differently and purposes:applets. JDBC API

It is helpful to understand the typical use situations before looking at the applets. There are usually two different situations that must be treated separately: and application. 4.1. Applet

Java

The web is currently used by most applets to download from the network as part of the text applet. There are database access and JDBC that can be used to access the applet to the database. Applets For example, a user may download a chart showing the stock history price. The applet, the Internet, gets the stock history price from the relational database. Applet

In the most general case, the use of the Internet is through unreliable boundaries. For example, get these from another company or an applet. The internet then calls this a "" applet occasion. However, it may also be downloaded over the LAN. In this case, the security of the client is still a problem. Applet

Typically different from traditional database applications in several ways: 1

). No applets are reliably and strictly limited to the operations they are allowed to perform. In particular, they are not allowed to access local files, and they are not allowed to establish a network connection to any database. 2

). In terms of Internet identity and connectivity to online databases, there are new problems in the context of the applet environment. 3

). When an Internet database may be miles away from you, the efficiency considerations are different. Compared with LAN, the applet database may encounter very different reaction time. 4.2. Application

Java

Java can also be used to build common applications and to use them on the client as a general application. We believe that as development tools become more and more, people begin to realize the need to improve the productivity of the program, as well as the other advantages of Java, Java this usage will become more and more popular. In this way, the code is trustworthy, and is allowed to read and write files to open Network connections, and so on, like other application code. Java

Perhaps the most common use of the intranet is within a company or intranet, so it might be a field Java combination. For example, a company would like to use and GUI its Java components tools to build his collaborative data model based cooperative software. These applications will access data on the LAN or WAN. Applications can do this. Java

There are many differences between the application of the intranet and the field customers combination. For example, the most natural way to calibrate a database is to use the name of a database, like the "and personnel" DBMS. Then the user wants the system to be able to locate specific machines, JDBC Driver,java and applications. 4.3.

Other occasions

There are some other interesting occasions: 1

). Applet-Validated (Trusted applets) Java refers to those that have been identified by virtual applets as being trustworthy. Applets are believed to be credible because they already have a specific key, or the user thinks it is appliction trustworthy from a particular source. They are the same as the application () applet in terms of security, but others, such as locating a database, are similar. 2

). Unlike the Java GUI, which uses client/server mode directly from the out DBMS to curvature Java servers, the three-tier access mode can be used. In this situation, RPC should use the program to make a call to the middle-tier service, the middle-tier service is online, and then it calls the database. These calls may be through the (Remote procedure Call) ORB or (object request broker) MIS. In both cases, the middle tier is best to use an object change. We hope that the three-tier structure will become more common, because for managers it gives them the opportunity to explicitly define legitimate operations on the public database. At the same time, the three-tier structure can provide many efficiency benefits. C

At present the middle layer is generally used or C +java + such language to complete. By optimizing the compiler to translate the word Java section code into efficient machine code, the middle tier can also be used for Java implementation. There are many good features (robustness, security, multithreading) to achieve the intermediate needs to achieve the purpose.

5.

Security Considerations JAVA

As a language on the network, JDBC must be very concerned about security. Based on the above discussion, we have to consider the security issue in the two main use situations: *

In Java Applications Java occasions, the trusted code is local, so it is also "" *

No Java applets have validated code that can not access data from local and other networks. 5.1. Jdbc

And applets are not validated by JDBC

General security rules that first Java must conform to. In addition: * JDBC

The applets must be deemed not to be reliable. * JDBC

No applets can allow unreliable access to the local database. *

A JDBC DriverManager has been to note the JDBC driver book is only access to its data source. *

An applet is also download can only access data to the server to which it comes. Jdbc

If an actuator layer is fully convinced that opening a connection to a database server does not cause authentication or permissions issues (which may be caused by programs running on a random host on the web), then it allows the IP to open such a connection. The database server does not restrict access through the applet address, mainly for example. (beware, this passage I may translate!!! Let's look at the original. These restrictions are quite cumbersome. But they are in line with the general restrictions. We do not need to let go of these restrictions. 5.2. Jdbc

and Java application Java

For a common Java program (for example, all using an applet code instead of unreliable) JDBC will be driven from the local classpath and allow applications to freely access files, remote servers, and so on. Applet

But with a sun.sql.Driver, if for some reason an unauthenticated class is obtained from a remote source, the driver can only match the code in the same place. 5.3. Driver

The security responsibility JDBC driver

Applets can be used in a variety of situations, so driver-makers follow certain simple security rules to avoid illegal database connections. Applet

If all drivers are downloaded from the web like a Java sample, then these principles will be unnecessary because the common security rules already limit it. But the driver must remember that once their drive is successful, the user will install these drivers on the local disk, and the driver will become a trusted part of the environment, so it must be assured that it will not be abused by the caller. So we encourage all driver writers to follow a certain security principle.

All of these principles are used when the connection is open. This formal drive and virtual machine Check whether the current caller is really able to connect to the specified database at the moment. Once the connection is established, no more checks are required. 5.3. 1.

Must be cautious when splitting TCP/IP connections if an drive TCP is trying to open a connection to a Java connection, the opening will be automatically checked by the applet's full management mechanism. This body checks if there is any in the current call stack, and JDBC, if so, limits the set of machines it can access. Therefore, the general drive TCP can be left to the virtual machine to build the Java state check. Jdbc

However, if an drive TCP is trying to share an applet a connection between multiple database connections, then the driver must be responsible for checking whether each caller is really allowed to contact the target database. For example, if we open a TCP applet B to the machine for the Foobah, this does not mean that the applet B is automatically allowed to share the connection. Foobah can not have any access to the machine's TCP power. So before allowing a program to reuse a ready-made, even JDBC connection, the driver must check with the security authority to see if the current caller can access the link. This functionality is implemented through the following code. SecurityManager Security

= System.getsecuritymanager (); If

(Security! null=)

{Security.checkconnect

(HostName, PortNumber);

} security.checkconnect

If the connection is not allowed, then the square java.lang.SecurityException method will produce one. 5.3. 2. Check all local files to access JDBC

If an acquisition requires access to data on the local machine, then he must be sure that the caller is allowed to open the file. For example: SecurityManager security

= System.getsecuritymanager (); If

(Security! null=)

{Security.checkread

(FileName);

} security.checkread

If access to a particular file is not allowed, then the square java.lang.SecurityException method will produce one. 5.3. 3.

Prepare for the worst!

Some drivers may use local methods to bridge the underlying database program. In these cases it is difficult to judge which local files will be accessed by the underlying function. Applet

In these environments, users must plan for the worst, and reject all database access issued by the download, unless the driver is completely convinced that access is not a problem. Jdbc-odbc

For example, a bridge ODBC connector must check the name of the source of the applet to ensure that it can only access its "origin". If you cannot determine the host name of a data source in some names, you can only deny this access. Applet

To determine whether a current caller is a trusted application or a JDBC driver must be able to check if the caller can write a random file: SecurityManager security

= System.getsecuritymanager (); If

(Security! null=)

{Security.checkwrite

(Foobaz ""); I.

}

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.