Solved

connection problem with derby when I want to insert new log messages into database

Posted on 2011-02-17
8
429 Views
Last Modified: 2012-08-13
I have a java application and I use Spring, Hibernate and embedded Derby database.
As I wanted to save my log messages into database, I defined a new Appender for log4j. When in the appendar I want to read from database or write into it I get an exception that the root cause is :
Caused by: java.sql.SQLException: No current connection.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
I guess the problem is with the Embedded Derby and its limitation for just one connection and It seems that appender can't use the same connection in my application(probably because it runs in another thread or something) and it want to get a new one and can't.
Any idea to solve this problem without using the network derby?
Any suggestions?
0
Comment
Question by:amirmb
  • 3
  • 3
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
derby can have more than one connection
your appender should open its own connection
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
 

Author Comment

by:amirmb
Comment Utility
Actually log4j JDBCAppender is not recommended from log4j guys. It has some problems I guess. And also I prefer to use hibernate rather than JDBC.
I'm not sure but I guess the embedded version of derby supports more than one connection just in the same JVM and same thread. I'm sure that you can't connect an embedded derby from different java applications. Maybe it has some issues with multi thread too. Maybe the problem is somewhere in hibernate. I'm not sure. If you have any experience about this problem, I will appreciate your help.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
thats right, steer clear of that. And yes you can have more than one connectiion in the same vm, though the thread is irrelevant.
As I mentioned above your appender should be using its own connection, and not sharing the application one or you will have threading issues.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>Actually log4j JDBCAppender is not recommended from log4j guys.

That's true, but log4j is itself superseded, so if you ARE worried about support and future-proofing, you should probably be using Logback and not writing your own db appender, but using their DBAppender:

http://logback.qos.ch/manual/appenders.html
0
 

Accepted Solution

by:
amirmb earned 0 total points
Comment Utility
Thank you for all your help. I found my problem. It was stupid actually. My appender was using the hibernate and DAOs to write into database and the service and DAO implementation wanted to generate new logs again. So it was kind of an infinite loop. And as it was transactional(I was using Spring services), the connections were passing the limit of connections before I get stackoverflow or heap exception.
Thanks again.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
So it already is using it's own connection, you should be fine then.
Good to hear your problem is resolved.
0
 

Author Closing Comment

by:amirmb
Comment Utility
The problem was just a infinite loop. When you want to create a new logAppender, you should always be sure that your appender doesn't call any code that wants to log again. otherwise you'll face an infinite loop
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Read about achieving the basic levels of HRIS security in the workplace.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now