It is very easy to debug with the Ibatis work program at the same time. Ibatis has built-in log support and is suitable for the following log libraries, and searches for them in this order.
You can use any of the libraries listed above in Ibatis.
Commissioning and log4j:
Let's say you want to use log4j, which is the best log record. Before proceeding, you need to cross-check the following points:
Below is a log4j.properties file. Note that some of the lines are commented out. You can cancel them if you need additional debugging information.
# Global Logging Configurationlog4j.rootlogger=error, stdoutlog4j.logger.com.ibatis=debug# shows SQL of prepared statements#log4j.logger.java.sql.connection=debug# shows parameters inserted into prepared statements# log4j.logger.java.sql.preparedstatement=debug# shows Query results#log4j.logger.java.sql.resultset=debug# log4j.logger.java.sql.statement=debug# Console outputlog4j.appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.layout= org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%5p [%t]-%m%n
You can find the complete log4j document from the Apaches website: log4j documentation.
IBATIS Debug Example:
The following Java class is a very simple example of initializing and then using the Java Application log4j log Library. It is located in the properties file mentioned above in Classpath.
ImportOrg.apache.log4j.Logger;Importcom.ibatis.common.resources.Resources;Importcom.ibatis.sqlmap.client.SqlMapClient;ImportCom.ibatis.sqlmap.client.SqlMapClientBuilder;ImportJava.io.*;Importjava.sql.SQLException;ImportJava.util.*; Public classibatisupdate{StaticLogger log =Logger.getlogger (ibatisupdate.class. GetName ()); Public Static voidMain (string[] args)throwsioexception,sqlexception{Reader Rd= Resources.getresourceasreader ("Sqlmapconfig.xml"); Sqlmapclient SMC=Sqlmapclientbuilder.buildsqlmapclient (RD); /*This would inserts one record in Employee table.*/Log.info ("Going to update record ..."); Employee Rec=NewEmployee (); Rec.setid (1); Rec.setfirstname ("Roma"); Smc.update ("Employee.update", REC); Log.info ("Record updated successfully"); Log.debug ("Going to read records ..."); List<Employee> EMS = (list<employee>) Smc.queryforlist ("Employee.getall",NULL); Employee em=NULL; for(Employee e:ems) {System.out.print (" " +E.getid ()); System.out.print (" " +e.getfirstname ()); System.out.print (" " +e.getlastname ()); System.out.print (" " +e.getsalary ()); EM=e; System.out.println (""); } log.debug ("Records Read successfully"); }}
Compile and run:
Here are the steps to compile and run the above software. Make sure that you have set the path and classpath appropriately before compiling and executing.
Create the Employee.xml as shown above.
Create the Employee.java as shown, and compile it.
Create the Ibatisupdate.java as shown, and compile it.
Create the Log4j.properties file as shown in.
Executes the ibatisupdate binary to run the program.
will get the following result and record the update in the employee table, then the same record will be read out from the employee table.
DEBUG [main]-Created connection 28405330-returned connection 28405330-Checked out connection 2840533 0-returned connection 28405330 to pool. 1 Roma Ali 2 Zara Ali 3 Zara Ali 5000
Debugging method:
In the example above, we only use the info () method, but you can use any of the following methods as you want:
Public void Trace (Object message); Public void Debug (Object message); Public void info (Object message); Public void warn (Object message); Public void error (Object message); Public void Fatal (Object message);
Series Articles:
MyBatis know how much (1)
MyBatis know how much (2)
MyBatis know how much (3)
MyBatis know how (4) The advantages of MyBatis
MyBatis know how much (5) Business object model
MyBatis know how (6) presentation layer and business logic layer
MyBatis know how much (7) persistence layer
MyBatis know how (8) relational database
MyBatis know how (9) different types of databases
MyBatis know how (10) application database
MyBatis know how (11) Enterprise database
MyBatis know how much (12) Private Database
MyBatis know how much (MyBatis) How to solve common problems in database
MyBatis know how (14) Decentralized database system
MyBatis know how much (15) data Model
MyBatis know how much (mybatis) map
MyBatis know how many () MyBatis and JDBC
MyBatis know how much (MyBatis) system
MyBatis know how much (mybatis) operation
MyBatis know how much () mybatis read operation
MyBatis know how much (21) Update operation
MyBatis know how much (mybatis) delete operation
MyBatis know how much (mybatis) results map
MyBatis know how much (24) stored procedures
MyBatis know how much (25) dynamic SQL
MyBatis know how much (26) commissioning