When the scale of an application was small, using JDBC was sufficient for development. However, as the number of internet users exploded and application functionality became more complex, the limitations of developing with traditional JDBC became apparent.
When developing with the traditional JDBC approach, not only did developers have to implement numerous repetitive SQL statements, but the SQL queries themselves also became intricate. As a result, naturally, database-related frameworks like MyBatis or Hibernate emerged.
As the number of internet users surged and application functionality grew more complex, the limitations of developing with traditional JDBC became apparent. Developers were required to implement numerous repetitive SQL statements, and the complexity of these queries increased. As a result, database-related frameworks like MyBatis or Hibernate naturally emerged.
The traditional process of integrating JDBC involves:
1. Establishing a connection
2. Creating a Statement object
3. Sending SQL queries
4. Retrieving results
5. Closing resources
Disadvantages of this approach include:
To address these issues, the MyBatis framework was developed.
As application functionality becomes more complex, the associated SQL queries tend to become several lines long. Handling lengthy SQL queries as plain strings can be inconvenient. This approach leads to frequent errors during SQL execution and poses maintenance challenges.
With MyBatis, even complex SQL queries can be used in a standardized way, similar to how SQL statements are used in tools like SQL Developer. This not only simplifies developer tasks but also enhances code readability.
Characteristics of the MyBatis framework include:
MyBatis Framework Structure
In short:
When connecting to a database, pre-written SQL queries are stored in SqlMapConfig.xml. When the application interacts with the database, the required data for these SQL queries is stored in corresponding parameters. These parameters are subsequently passed to the associated SQL queries.
The passed parameters and SQL queries are combined to form an SQL statement, which is sent to the DBMS for execution. The outcome of the execution is returned to the application, formatted according to the specified data types.