JDBC Overview and Connection database

Source: Internet
Author: User

First, JDBC Introduction:

JDBC (Java Data Connectivity,java database connection) is a JAVAAPI for executing SQL statements that provides unified access to a variety of relational databases, consisting of a set of classes and interfaces written in the Java language.

Second, the JDBC principle:

JDBC is the previous Sun company defined a set of access to the database interface (no specific implementation), a set of standards, the specific implementation is by the major database manufacturers to implement , each database manufacturers have their own JDBC implementation, that is, the JDBC driver implementation class, Java applications connect to the specified database and need to use the JDBC driver provided by the manufacturer to connect. (This is actually a Java polymorphic withdrawal, an interface can have a lot of specific implementation)

Third, JDBC Connection database steps

1. Load Driver

2. Connect to the database

3. Manipulating databases with statements

4. Close the database connection and release the resources;

Iv. Configuring Database Drivers in Eclipse projects (e.g.,Mysql-connector-java-5.1.40-bin.jar)

Right-click the project->build path->configure Build path->add exteranljars ....

V. Load data-driven

mysql driver name: Com.mysql.jdbc.Driver

Loading mode: Class.forName (driver name);

Vi. connection and closure of databases

1. DriverManager drive Management class, mainly responsible for obtaining a database connection;

2. Connection address format for MySQL database

JDBC:MYSQL://IP Address: Port number/database name

JDBC Protocol: The protocol in the JDBC URL is always jdbc;

Sub-Protocol: The name of the driver name or database connection mechanism, such as: MySQL

Sub-name: A way to identify a database. Must follow standard URL naming for "//hostname: Port/Database Name"

3. Connection interface to a specific database connection (session).

void Close () : Frees the database and JDBC resources for this connection object immediately, rather than waiting for them to be freed automatically

Upper and Lower code:

JDBC Overview and Connection database

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.