Solved

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

Posted on 2011-02-17
8
437 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
ID: 34920150
derby can have more than one connection
your appender should open its own connection
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34920404
0
 

Author Comment

by:amirmb
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.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 92

Expert Comment

by:objects
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.
0
 
LVL 86

Expert Comment

by:CEHJ
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:

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

Accepted Solution

by:
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 34922666
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
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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Service Catalogue and Data Migration doc 3 40
How to convert from xls to xlsx using java 7 37
Java: anonymous class 4 17
printf performancy 11 33
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

786 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