How to print Log4j java sql logger -



How to print Log4j java sql logger -

i want utilize log4j java , sql. want print java , sql logs without using "logger.debug("log4j logger")" in class.

below class , log4j properties used

package com.log4j; import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import org.apache.log4j.logger; import org.apache.log4j.propertyconfigurator; public class logtest { public static void main(string[] args) throws exception{ final logger logger = logger.getlogger(logtest.class); propertyconfigurator.configure("log4j.properties"); seek { class.forname("oracle.jdbc.oracledriver"); connection conn = drivermanager.getconnection("xxx", "yyy", "zzz"); string inserquery = "insert table1 (name,id) values (?,?)"; preparedstatement prestat = conn.preparestatement(inserquery); prestat.setstring(1, "test"); prestat.setstring(2, "2"); prestat.executeupdate(); } grab (exception ex) { system.out.println("exception: " + ex.getmessage() + ""); } } }

below log4j properties

log4j.rootlogger=debug,ca log4j.logger.java.sql=debug log4j.logger.java.sql.resultset=debug log4j.logger.java.sql.connection=debug log4j.logger.java.sql.statement=debug log4j.logger.java.sql.preparedstatement=debug log4j.appender.ca=org.apache.log4j.consoleappender log4j.appender.ca.layout=org.apache.log4j.patternlayout log4j.appender.ca.layout.conversionpattern=%-4r [%t] %-5p %c %x - %m%n

please advise.

any help appreciated

thanks

its u created variable never used why create it, improve if utilize

logger.error("exception: " + ex.getmessage() + "");

instead of

system.out.println("exception: " + ex.getmessage() + "");

java log4j log4jdbc

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -