-java-jdbc Getting Started

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Jdbc:

JDBC full name is Java DataBase Connection

The JDBC API is both an interface and why it is an interface:

1. Unified operation

2. Transferring responsibility to the database developer

How to add a jar package:

Eclipse General Engineering Add:

1. Locate the appropriate database jar package

2. Copy the jar package directly to the project catalog

3. Adding to the compilation environment

This method is to remove the package, must be lifted to delete

Eclipse maven Maven Project add

1. First enter the Central warehouse www.mvnrepository.com

2. Then search for MySQL

Then select the version you want to download and add the dependent copy to eclipse

Oracle jar Package Download:

can also be found directly in Oracle's installation directory

The JDBC interface describes: (these interfaces are all stored under the java.sql package)

The DriverManager     driver Administrator is used to create the Connectionconnection         database Connection object statement           SQL execution Object PreparedStatement   ResultSet Query result set resultsetmetadata   query table structure callablestatement    stored procedure Call

What is the driver, the driver is the implementation of the JDBC interface operation class Mysql JDBC API jar

Java Connection Database steps: 1. Find the jar package >> add to the project first

If it's maven, just set the dependency right.

2. Start the database to ensure that the database can be connected in network mode

3. Load driver (some database driver packages can be loaded automatically) Class.forName ("Com.mysql,jdbc. Driver ");

Use class to load classes so that static members are initialized

Loading the driver class, its static block executes, and the static block is immediately registered and driven to the driver administrator class

New Com.mysql.jdbc.Driver (); New can also initialize the load class

The properties inside the Com.mysql.jdbc.Driver.class call can also initialize the load class.

Learn to see if the database jar has meta-inf/service this folder, which says it automatically loads

4. Create a Connection object using the DRIVERMANAGR administrator

It is generally filled with three data, the following three:

Drivermanager.getconnection ("", "", "");

MySQL URL Many ways: 1.jdbc:mysql:///mysql default local and default port 3306

2.jdbc:mysql://127.0.0.1:3306/mysql This is the definition of the address port

1. URL  Connect What database            server address            server port            database name            other settings

2. User name 3. password

This is the complete syntax for the Java connection database.

-java-jdbc Getting Started

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.