The problem with traditional JDBC is as follows:
1. Database connection creation, release frequently caused the waste of West Rong resources, thus affecting system performance, using database connection pool can solve the problem.
2.sql statements in code hard-coded, resulting in code maintenance, the actual application of SQL changes may be large, SQL code and Java code is not separated to maintain inconvenient.
3. Using PreparedStatement to pass parameters to a placeholder there is a hard-coding problem because the condition of the WHERE clause in SQL is not deterministic, and it is also inconvenient to modify
4. There is a hard coding problem in the result set parsing, the change of SQL leads to the change of parsing code and the system maintenance is inconvenient.
MyBatis's solution to traditional JDBC
1, the database connection creation, the release frequently causes the system resources to waste thus affects the system performance, if uses the database connection pool solves this problem.
Workaround: Configure the data connection pool in Sqlmapconfig.xml and use connection pooling to manage database links.
2, SQL statements written in the code cause code is not easy to maintain, the actual application of SQL changes may be large, SQL changes need to change the Java code.
WORKAROUND: Configure the SQL statement to be detached from the Java code in the Xxxxmapper.xml file.
3. It is troublesome to pass arguments to SQL statements because the WHERE condition of the SQL statement is not necessarily, possibly more or less, and the placeholder needs to correspond to parameter one by one.
Resolution: MyBatis Automatically maps Java objects to SQL statements, defining the type of input parameters through ParameterType in statement.
4, the result set parsing trouble, SQL changes lead to parsing code changes, and need to traverse before parsing, if the database records can be encapsulated into Pojo object parsing is more convenient.
Resolution: MyBatis automatically maps SQL execution results to Java objects, defining the type of output results through Resulttype in statement.
The disadvantage of traditional JDBC and the solution of MyBatis