Java web Database Development 1. java web Database Development

Source: Internet
Author: User
Tags web database

Java web Database Development 1. java web Database Development

A complete database deployment architecture usually consists of two parts: client and server. The client encapsulates the database Request and sends it to the server. After the server completes execution, it returns the result to the server.

Take mysql as an Example

Introduction to database access by java applications

JDBC: The application calls a unified interface to access any database, shielding us from the implementation details of the interaction protocol between the client and the server.

For java, JDBC is a class library, and for databases, JDBC is an interface specification.

With JDBC, the application becomes simpler and the efficiency of program development is improved. java web is cross-platform for different databases, and is based on JDBC, we can develop a more powerful framework.

JDBC Architecture

In terms of the architecture, JDBC is divided into two layers:

Upper-layer API: communicates with java web programs

Underlying database driver layer: connects to a specific database, which is generally provided by various database vendors.

Before using JDBC, we need to prepare a backend instance of the mysql database. The java application can read the name of a person.

The jdbc api involves several important java classes:

1. Driver & DriverManager

Driver is actually an interface that defines the functions that each Driver must implement and is the abstraction of the Driver. You can perform operations on each Driver by operating the Driver interface.

DriverManager is the Driver management class. You can register a Driver with DriverManager using class. forname. Then, DriverManager calls the Driver through the getConnection method to establish a physical connection to the backend database.

The Connection object represents a physical link of the java application to the backend database.

The Connection object creates one or more Statement objects.

Statement object: it is an SQL container that stores SQL statements and performs the delete operation of update query,

Execute a database query using the executeQuery method of the Statement object to obtain a set of database query results. The set is represented by the ResultSet object.

Delete and update using the execute and executeUpdate statements of the Statement object. The returned INT value indicates how many database records are affected by the operation.

Introduction to the ResultSet object:

Represents the results of SQL queries. Relational databases are essentially binary tables, And the ResultSet object is actually a binary table composed of rows and columns.

They are the next row and the first row. Locate a row, before the first row, and after the last row.

After the row is adjusted, it must correspond to the column:

Column name or column number (sorted from 0)

An exception may be thrown during the operation and sqlException will be processed.

GetConnection (DB_URL, UDER, PASS) has three parameters.

 

Build a Java Web Program

Five steps

1. javaManger registers a driver

2. Use the getConnection method to create a link to the backend database.

3. Execute SQL statements by placing SQL statements in the Statement container

4. The ResultSet object determines the rows and columns and obtains the values of a column in a row.

5. Clear Resources

To be continued...

Related Article

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.