MyBatis Console Print SQL statement implementation Code _java

Source: Internet
Author: User
Tags log4j

MyBatis Introduction

MyBatis is an excellent persistence layer framework that supports common SQL queries, stored procedures, and advanced mappings. MyBatis eliminates the manual setting of almost all JDBC code and parameters and the retrieval encapsulation of the result set. MyBatis can use simple XML or annotations for configuration and raw mappings, mapping interfaces and Java Pojo (Plain old Java Objects, normal Java objects) to records in the database.

Below look at the MyBatis console print SQL statement

1. First move the Ibatis log4j run level to debug to print out the SQL statements Ibatis run on the console

2. Add the following statement

# # #显示SQL语句部分
log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.simpledatasource=debug
Log4j.logger.com.ibatis.common.jdbc.scriptrunner=debug
Log4j.logger.com.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debug
log4j.logger.java.sql.connection= DEBUG
log4j.logger.java.sql.statement=debug
log4j.logger.java.sql.preparedstatement=debug

Below look at the MyBatis and Ibatis console print SQL statements

 #将ibatis log4j Run level to debug can print out Ibatis run SQL statement log4j.rootlogger=debug,stdout in the console. LogFile ### output log information to the console ### Log4j.appender.stdout=org.apache.log4j.consoleappender #log4j. appender.stdout.target=
System.err log4j.appender.stdout.layout=org.apache.log4j.simplelayout ### Output log information to file: Jbit.log ###
Log4j.appender.logfile=org.apache.log4j.fileappender Log4j.appender.logfile.file=d:/test.log Log4j.appender.logfile.layout=org.apache.log4j.patternlayout log4j.appender.logfile.layout.conversionpattern=%d
{yyyy-mm-dd HH:mm:ss}%F%p%m%n # # #显示SQL语句部分 Log4j.logger.com.ibatis=debug Log4j.logger.com.ibatis.common.jdbc.simpledatasource=debug log4j.logger.com.ibatis.common.jdbc.scriptrunner= DEBUG Log4j.logger.com.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debug log4j.logger.java.sql.connection= DEBUG log4j.logger.java.sql.statement=debug log4j.logger.java.sql.preparedstatement=debug 

The above is a small set to introduce the MyBatis console print SQL statement Implementation code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.