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

Posted on 2011-02-17
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?
Question by:amirmb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 92

Expert Comment

ID: 34920150
derby can have more than one connection
your appender should open its own connection
LVL 86

Expert Comment

ID: 34920404

Author Comment

ID: 34920741
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.
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 92

Expert Comment

ID: 34920813
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.
LVL 86

Expert Comment

ID: 34921118
>>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:

Accepted Solution

amirmb earned 0 total points
ID: 34922114
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.
LVL 92

Expert Comment

ID: 34922666
So it already is using it's own connection, you should be fine then.
Good to hear your problem is resolved.

Author Closing Comment

ID: 35145558
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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

636 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