How JDBC is programmed

Source: Internet
Author: User

In the way JDBC is programmed, we use JDBC programming as an example of a simple query, as follows:

As you can see from the above, JDBC programming generally takes the following steps:
1. Load Database Driver

2. Create and obtain a database connection

3. Creating a JDBC Statement object

4. Set the SQL statement

5. Set parameters in SQL statement (using PreparedStatement)

6. Execute SQL via statement and get results

7. Parse the results of SQL execution

8. Releasing resources (ResultSet, PreparedStatement, connection)

You can see that all JDBC programming has many of the same steps, such as loading drivers, getting connections, and so on. There are also a number of different places, such as SQL statements, parameters, query results, and so on. JDBC Programming primarily has the following issues:

1, the database link creation, the release frequently causes the system resources to waste thus affects the system performance, if uses the database link pool solves this problem.

2, SQL statements in code hard-coded, resulting in code is not easy to maintain, the actual application of SQL changes may be large, SQL changes need to change the Java code.

3, the use of PreparedStatement to the possession of the symbol parameters are hard-coded, because the SQL statement where the condition is not necessarily, may be more or less, modify the SQL to modify the code, the system is not easy to maintain.

4, the result set parsing has hard coding (query column name), SQL changes lead to parsing code changes, the system is not easy to maintain, if the database records can be encapsulated into Pojo object resolution is more convenient.

MyBatis is a framework that encapsulates the above steps in template mode, implements the same parts, configures different parts in the configuration file, and supports mapping of parameters and query conditions, result sets, and Java object mappings to simplify programming.

How JDBC is programmed

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.