Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Problem with JDBCAppender

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to log messages to database using jdbcappender.
Also I want the messages should be written to a text file simultaneously.

My property file is:

log4j.rootLogger=debug, R,searchdb

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=E:\\jboss-4.0.5.GA\\server\\default\\conf\\messagelog1.log
log4j.appender.R.layout=org.apache.log4j.SimpleLayout

log4j.appender.searchdb=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.searchdb.Driver=net.sourceforge.jtds.jdbc.Driver
log4j.appender.searchdb.URL=jdbc:jtds:sqlserver://20.90.20.42:1433;DatabaseName=weblog
log4j.appender.searchdb.user=civil
log4j.appender.searchdb.password=p545
log4j.appender.searchdb.layout=org.apache.log4j.PatternLayout
log4j.appender.searchdb.sql=INSERT INTO searchapplog (ipaddress) VALUES ('%X{ipaddress}')

Now my class named testservlet:

public class testservlet extends HttpServlet {

private final static Logger log = Logger.getLogger(testservlet.class);
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.info("DATE:"+todayStr);
log.info("TIME:"+todaytime);
MDC.put("ipaddress",request.getRemoteAddr());

}
}

I get output with some null rows inserted in the database along with ipaddress.Or sometimes I get duplicate rows inserted in database.
Why is it so?
I just want the database should have ipaddress value inserted and the log file should have date and time inserted.
What settings I have to change in configuration file?

Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic