JDBC Database 1

Source: Internet
Author: User
Tags odbc

A database is a warehouse that organizes, stores, and manages data in accordance with its data structure. There are many types of databases, ranging from simple tables that store a variety of data to systems that can store large data, and are widely used in various ways.
Introduction to Databases
J.Martin a more complete definition of the database: A database is a collection of related data that is stored together, is structured, has no harmful or unnecessary redundancy, and serves a variety of applications, and the storage of the data is independent of the
procedures; inserting new data into the database, modifying and retrieving the original data can be done in a common and controllable manner. When there are several databases in a system that are completely separate from each other, the system contains a "database collection".

The nature of data in a database
1: The integrity of the data
A database is a unit or an application of the General data processing system, it is to belong to the enterprise or business sector, groups and individuals of the relevant collection, the data in the database is based on a global perspective, it according to a certain data model
Be organized, described and stored. Its structure is based on the natural relationship between data, so as to provide all the necessary access path, and the data is not for an application, but for the whole organization, with the overall structural characteristics.
2: Data sharing
The data in the database is created for the information shared by many users, which has been removed from the limitation and restriction of the specific program. Different users can use the data in the database in their own usage, and multiple users can share data resources in the database at the same time, i.e.
Different users can access the same data in the database at the same time. Data sharing not only satisfies the requirement of each user for information content, but also satisfies the requirement of communication between each user.

Features of the


Database
1: Implementing data sharing
Data sharing includes the ability for all users to access data in the database at the same time, as well as the ability for users to use the database in various ways and to provide data sharing.
2: Reduce the redundancy of data
compared with the file system, because the database to achieve data sharing, so as to avoid the user to set up application files, reduce the amount of duplication, reduce data redundancy, maintain the consistency of data.
3: Data Independence
The independence of the data includes the logical structure of the database and the application being independent of each other, as well as changes in the physical structure of the data without affecting the logical structure of the data.
4: Centralized control of data
File management mode, the data in a decentralized state, different users or the same user in different processing of their files have no relationship. The database can be used to centralize the management and control of the library, and through the data model to represent the organization of various data and the number of the relationship between the
.
5: Data consistency and maintainability to ensure data security and reliability.
Security Control: To prevent data loss, error updates, and unauthorized use.
Integrity Control: Ensures the accuracy, effectiveness, and compatibility of data.
Concurrency control: Allows multiple access to data during the same time period, and prevents abnormal interactions between users,
Discovery and recovery of failures: a database management system provides a set of methods to detect faults and fix failures in a timely manner to prevent data corruption.
6: failback
Provides a set of methods by the database management system to detect failures and fix failures in a timely manner to prevent data corruption. The database system recovers the failure of the database system as soon as possible, which may be a physical or logical error. For example, error in the system
wrong operation caused by data errors, and so on.

The


JDBC Overview
jdbc (Java Data Base Connectivity,java database connection) is a JAVAAPI for executing SQL statements that provides unified access to a variety of relational databases. It consists of a set of classes and interfaces written in the Java language. JDBC provides a standard API for tools/
Data developers to build more advanced tools and interfaces that enable database developers to write database applications with pure JAVAAPI.
with JDBC, it is easy to send SQL statements to various relationships. In other words, with the JDBC API, you don't have to write a program to access the MySQL database, write a program specifically for accessing the Oracle database, write another program for accessing SQL Server, and so on, so programmers just need to write a program with the JDBC API. It can send SQL calls to the appropriate database. At the same time, the Java language and JDBC are combined so that programmers do not have to write different applications for different platforms, just write the program once to let it run on any platform, which is the Java language "write once, run everywhere" advantage, Providing a convenient way for conversations between Java applications and various databases allows developers to write database applications that are cross-platform with pure Java APIs.

Introduction to JDBC
The Java Database Connectivity architecture is a standard way to connect a database to a Java application. JDBC is an API for Java programmers and is an interface model for implementing providers of database Connectivity services. As a standard interface for program development, API,JDBC provides a standard method for database vendors and third-party middleware vendors to connect with databases. JDBC uses existing SQL standards and supports bridging with other database connectivity standards, such as ODBC. JDBC implements all these standards-oriented goals and simple, rigorous types define interfaces for high-performance implementations.
Java is a strong, secure, easy-to-use, easy-to-understand and automatic download from the Web, and is an excellent language for writing database applications. What it needs is a way for a conversation between a Java application and a variety of different types of databases, and JDBC is formally used as a mechanism for this purpose.
JDBC extends the functionality of Java, for example, by using Java and the JDBC API to publish Web pages containing applets that can be used by the applet from a remote database. An enterprise can also use JDBC to connect all employees to one or more internal databases over the Internet (in a timely manner, the computers used by these employees are various operating systems such as Windows, Macintosh, and Unix). As more and more programs start to use the Java programming language, the need for easy access to databases from Java is increasing.
By using a JDBC developer, it is easy to pass SQL statements to almost any database, and the process by which an application invokes JDBC to manipulate the database is actually the database vendor's responsibility to provide the JDBC driver. If you are replacing a database, you can change the database system by simply changing the driver and loading the new driver source into JDBC. The main functions of JDBC are as follows:
Establish a connection to a database or other data source.
Sends SQL commands to the database.
Processes the returned results of the database.

Four types of drivers for JDBC
In order to connect to a database, you must have a driver that is appropriate for that database. The JDBC driver mainly has the following 4 basic types.
1:JDBC-ODBC Bridge plus ODBC driver
JDBC-ODBC Bridge products through the ODBC Driver for JDBC access to the database, widely used to connect the database in a variety of environments. The Jdbc-odbc Bridge plus ODBC driver actually passes all JDBC calls to ODBC, and the local database driver code is called by ODBC. Note that you must load the ODBC binary code (and in many cases, the local database client code) onto each user machine that uses the driver. Therefore, this type of driver is best suited for enterprise networks (where client installation is not a major problem), or for application server code in Java-written three-tier architecture. It mainly has the following three characteristics:
Provides connectivity to all database capabilities on almost all platforms
It may be the only way to access a low-end desktop database, such as access, and to apply programs.
Easy to operate, suitable for beginners to learn.
The disadvantage is that the ODBC driver needs to be installed and loaded onto the target machine.
2: Local API and some Java-written drivers
This type of driver converts the JDBC call on the API on the client to a call to the database. This type of driver is much faster than the type 1 approach, but it still has some drawbacks: the need to install local code on the target machine.
The local interfaces that JDBC relies on are different for different Java Virtual machine vendors and different operating systems.
3:JDBC Network Pure Java Driver
This driver translates jdbc into a DBMS-independent network protocol, which is then transformed by a server into a DBMS protocol. This Web server middleware can connect its pure Java client to many different databases, and the specific protocol used depends on the provider. Typically, this is the most flexible JDBC driver, and it is possible for all of this solution providers to provide products suitable for use in the Internet. In order for these products to also support Internet access, they must handle the additional requirements of the web for security, access through firewalls, and so forth. It mainly has the following characteristics:
No local code is required on the client
Do not require any programs to be installed by customers
Most feature implementations are on the server side, so this driver can be designed to be very small and can be loaded into memory quickly
The disadvantage is that the middle tier still needs to configure other database drivers, and because there is an intermediate layer to pass the data, it is not the best execution efficiency.
4: Local protocol pure Java driver
This type of driver contains the access protocol for a particular database, which allows the client to communicate directly with the database, with the following advantages for drivers:
High efficiency, fast speed.
The driver can be downloaded dynamically.
The disadvantage is that you need to download different drivers for different databases.

JDBC Support for b/S and C/s mode
The JDBC API supports both the two-tier mode (c/s) of database access and the three-tier mode (b/s). In a two-tier model, a Java applet or application will talk directly to the database. This will require a JDBC driver to communicate with the particular database management system that you are accessing. The user's SQL statement is sent to the database, and the result is sent back to the customer. The database can be located on another computer, and the user is connected to it over the network. This is called the user/server configuration, where the user's computer is the client and the computer that provides the database is the server. A network can make an intranet (it can connect company employees), or it can be the Internet.
In a three-tier model, the command is first sent to the "middle tier" of the service and then sent to the database by the SQL statement. The database processes the SQL statement and sends the structure back to the middle tier, which then sends the results back to the user. Mis executives have found the three-tier model attractive because of the availability of intermediate layers to control access to corporate data and the types of roots that can be made. Another benefit of the middle tier is that the user can take advantage of an easy-to-use advanced API, and the middle tier will convert it to the appropriate low-level invocation. Finally, in many cases the three-tier structure provides some performance benefits.
So far, the middle tier is usually written in a language such as C or C + +, which executes faster. However, with the introduction of the optimization compiler, which translates Java byte code into an efficient machine-specific code, it becomes more practical to implement the middle tier in Java. This will be a big step forward, and it's one of the many advantages that people can take advantage of Java, such as robustness, multithreading, security, and so on. JDBC is important for accessing databases from the middle tier of Java.

java.sql Bag
Many interfaces and classes are defined in the java.sql package, but not many are often used. Here are a few common interfaces and classes.
1: Load Driver Interface: Driver
Java.sql.Driver is the interface that all JDBC = drivers must implement.
2: Management driver class: DriverManager
The DriverManager class is the management layer of JDBC, which acts between the user and the driver. It tracks the available drivers and establishes a connection between the database and the driver. When DriverManager fires the getconnection () method, the DriverManager class first finds a driver that can accept the data URL from the drive pool it has loaded, and then requests that the driver connect to the database using the associated database URL. The getconnection () method establishes a connection to the database.
3: Database connection interface: Connection
The Connection object represents a connection to a database, that is, to establish a connection between the loaded driver and the database, you must create an instance of the connection class that includes the database information.
The connection process includes the SQL statement that was executed and the results returned on that connection. An application can have one or more connections to a single database, or it can be connected to many databases. The DriverManager getconnection () method will be built on the connection connection of the database defined in the JDBC URL, with the following code:
Connection con=drivermanager.getconnection (URL, login,password);
4:sql Declaration Interface Statement
Java.sql.Statement provides a SWL statement that runs on a grassroots connection and accesses the results. The connection interface provides a way to generate statement. In general, we can get an example of statemenet through the Connection.createstatement () method. Statement provides a number of methods, the most commonly used methods are as follows:
Execute () runs the statement, returning whether there is a result set.
ExecuteQuery () runs the query statement, returning the Reaultset object.
Executeupdate () runs an update operation that returns the number of rows updated.
Addbatch () Increments the batch statement.
ExecuteBatch () Executing a batch statement
Clearbatch () Clear Batch statement

JDBC Database 1

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.