0% found this document useful (0 votes)
15 views3 pages

Ibatis Debugging

The document provides guidance on debugging iBATIS applications using built-in logging support with libraries such as Log4J. It includes a sample Java class demonstrating how to configure Log4J for logging SQL operations and provides steps for compiling and running the example. Additionally, it lists various logging methods available for different debugging needs.

Uploaded by

balajsamy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Ibatis Debugging

The document provides guidance on debugging iBATIS applications using built-in logging support with libraries such as Log4J. It includes a sample Java class demonstrating how to configure Log4J for logging SQL operations and provides steps for compiling and running the example. Additionally, it lists various logging methods available for different debugging needs.

Uploaded by

balajsamy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IBATIS - DEBUGGING

[Link] Copyright © [Link]

It is easy to debug your program while working with iBATIS. iBATIS has built-in logging support and it works with
the following logging libraries and searches for them in this order.

Jakarta Commons Logging (JCL).

Log4J

JDK logging

You can use any of the above listed libraries alongwith iBATIS.

Debugging with Log4J:

Assuming you are going to use Log4J, which is my favorite for logging. Before proceeding you need to cross check
following points:

The Log4J JAR file (log4j-{version}.jar) should be in the CLASSPATH.

You have [Link] available in the CLASSPATH.

Following is the of a [Link] file. Note that some of the lines are commented out. You can uncomment them if
you need additiona debugging information.

# Global logging configuration


[Link]=ERROR, stdout

[Link]=DEBUG

# shows SQL of prepared statements


#[Link]=DEBUG

# shows parameters inserted into prepared statements


#[Link]=DEBUG

# shows query results


#[Link]=DEBUG

#[Link]=DEBUG

# Console output
[Link]=[Link]
[Link]=[Link]
[Link]=%5p [%t] - %m%n

You can find complete documentation for Log4J from Apaches site: Log4J Documentation.

iBATIS Debugging Example:

The following Java class is a very simple example that initializes, and then uses, the Log4J logging library for Java
applications. We would use above mentioned property file which lies in CLASSPATH.

import [Link];

import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link].*;

public class IbatisUpdate{


static Logger log = [Link](
[Link]());

public static void main(String[] args)


throws IOException,SQLException{
Reader rd = [Link]("[Link]");
SqlMapClient smc = [Link](rd);

/* This would insert one record in Employee table. */


[Link]("Going to update record.....");
Employee rec = new Employee();
[Link](1);
[Link]( "Roma");
[Link]("[Link]", rec );
[Link]("Record updated Successfully ");

[Link]("Going to read records.....");


List <Employee> ems = (List<Employee>)
[Link]("[Link]", null);
Employee em = null;
for (Employee e : ems) {
[Link](" " + [Link]());
[Link](" " + [Link]());
[Link](" " + [Link]());
[Link](" " + [Link]());
em = e;
[Link]("");
}

[Link]("Records Read Successfully ");

}
}

Compilation and Run:

Here are the steps to compile and run the above mentioned software. Make sure you have set PATH and CLASSPATH
appropriately before proceeding for the compilation and execution.

Create [Link] as shown above.

Create [Link] as shown above and compile it.

Create [Link] as shown above and compile it.

Create [Link] as shown above.

Execute IbatisUpdate binary to run the program.

You would get following result, and a record would be updated in EMPLOYEE table and later same record would be
read from the EMPLOYEE table.

DEBUG [main] - Created connection 28405330.


DEBUG [main] - Returned connection 28405330 to pool.
DEBUG [main] - Checked out connection 28405330 from pool.
DEBUG [main] - Returned connection 28405330 to pool.
1 Roma Ali 5000
2 Zara Ali 5000
3 Zara Ali 5000

Debug Methods:
In the above example we used only info() method but you can use any of the following methods as per your
requirements:

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);

You might also like