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