JDBC-related knowledge points

Source: Internet
Author: User

1. Functions of JDBC

JDBC is short for Java DataBase Connectivity and is a standard API for various Java applications to connect to various DataBase management systems. Each database management system provides its own JDBC driver through which developers can interact with the database.

2. What information do I need to know when developing applications using JDBC?

First, you must have a driver that knows the driver name, URL format, and basic database information: IP address, port, database, user name, and password.

3. JDBC APIs

Driver: establishes a connection with the database.

DriverManager: Manage drivers

Connection: indicates a session with the database. No matter what operation is performed, a Connection must be established first.

Statement: used to execute SQL statements

ResultSet: indicates the query result set.

DataSource: data source, used to obtain connections in the connection pool

4. Basic database connection process

Load driver

Create a connection object

Create statement object

Write SQL statements

Execute SQL statements using statement objects

If a result set is used to process the result set

Close the result set object (if any), close the statement object, and close the connection object.

5. How to load the driver

Class. forName ("driver name "):

6. How to create a connection

The getConnection method of DriverManager has three parameters: the first parameter is the URL, the second parameter is the user name, and the third parameter is the password.

7. How to Create statement objects

Create a Statement object: con. createSteatement ()

Create a PrepareStatement object: con. prepareStatement (SQL statement );

Create a CallableStatement object: con. prepardCall (stored procedure name)

8. How to execute SQL statements

Execute the select statement: the executeQuery method of the statement object

Execute the insert delete update statement: the executeUpdate method of the statement object

9. When the result set is obtained, the Pointer Points to the front of the first record. If one record exists, use if (rs. next (). if multiple records exist, use while (rs. next ())

10. How to obtain a column in the result set?

Using methods such as rs. getString, the method parameter specifies the column sequence number or column name.

11. How do I close objects?

Close the result set, close the statement object, and close the connection object.

12. How to Use JDBC for transaction processing?

Con. setAutoCommit (false );

Execute SQL statements

Con. commit submit

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.