MySQL Getting started is simple: Java accesses MySQL database

Source: Internet
Author: User

1. Connect to database 1.1 download install driver

Java accesses the MySQL database through JDBC (Java database Connectivity,java connection). The JDBC programming interface provides interfaces and classes to connect to the MySQL database, and then processes the results of the SQL statement execution.

1) Download MySQL connector/j driver

http://dev.mysql.com/downloads/file/?id=460363

2) myeclipse import JDBC Driver

window| Perference path| User Libraries New library file: Mysql-jdbc Add JARs

Right-click the project name Build Path, ADD Library, User Library, Next, select Mysql-jdbc

1.2 Connecting to MySQL Database
There are drivermanager classes, connection interfaces, statement interfaces in the java.sql package, ResultSet interface DriverManager class: Managing Drivers and connecting databases connection interfaces: Managing established database connections statement interfaces: Executing SQL statements resultset interfaces: Storing records returned by the database

1) Specify the type of JDBC driver using forname () in the Java.lang.Class class

2) Connect to the database using the DriverManager class and the connection interface

2. Manipulating the database

1) Create statement object

2) Querying data using the SELECT statement

3) Insert Update or delete data

4) Execute arbitrary SQL statements

5) Close the created object

3. Backing up and restoring Databases

1) Backup

MySQL Getting started is simple: Java accesses MySQL 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.