0

I wrote a simple program to execute a particularly large SQL file on a mysql database . The program is working fine, but because the SQL has large amount of data , the log generated is very large and unreadable. Is there some way to make jdbc print only errors or make it write the log into a file .

born
  • 265
  • 3
  • 18

1 Answers1

2

You can use any Logger, like Log4j and log in Catch statement:

Steps to follow:
Download latest log4j distribution.
Add log4j’s jar library into your program’s classpath.
Create log4j’s configuration.
Initialize log4j with the configuration.
Create a logger.
Put logging statements into your code.

 Logger logger = Logger.getLogger(MyClass.class);

try {
      // Your risky code goes between these curly braces!!!
 }
 catch(Exception ex) {
    // Log your errors here
       logger.info("This is my first log4j's statement");

}
 finally {
      // Your must-always-be-executed code goes between these 
     // curly braces. Like closing database connection.
  }

`

Ref:http://www.codejava.net/coding/how-to-configure-log4j-as-logging-mechanism-in-java

mohit sharma
  • 1,050
  • 10
  • 20