This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom JDBC connection listener

 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a query here, i m not sure whether this is technically possible or not.

Is it possible to write and implement a listener class which will be called for every JDBC connection created/closed from the appplication server to DB server.

Whenever my application requests for a connection object to Oracle DB Server then this listener should be called and same way while closing. (similar to httpsessionlistener class).

Is there any way by which i can achieve this ???

P.S. I m using Weblogic 9.2 application server and Oracle 10G with JSF 1.1 framework
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35969
422
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can think of two ways. One is to write a wrapper for the datasource/connection so you know when a connection is requested. The other is to use aspect oriented programming to do the same thing.
 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:I can think of two ways. One is to write a wrapper for the datasource/connection so you know when a connection is requested. The other is to use aspect oriented programming to do the same thing.


Thanks Jeanne. Wrapper class logic worked.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On oracle you can also track sessions using after logon and before logoff triggers.
 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ireneusz Kordal wrote:On oracle you can also track sessions using after logon and before logoff triggers.
Hi Ireneusz, Can you explain in a little brief about this ?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinodh Sa wrote:
Ireneusz Kordal wrote:On oracle you can also track sessions using after logon and before logoff triggers.
Hi Ireneusz, Can you explain in a little brief about this ?


I show you a simple example.
These triggers are created at schema level (by user test):


Then we fire a little program in java that connects to and disconnects from oracle


and here is the result:


The last 21st login is because I logged as test with sqlplus - triggers are fired always, after each login and logoff.


edit
These triggers must be carefully tested, especially afterlogon trigger, because when error occurs this prevents user from login in.
In this case DBA must drop this trigger.
 
Vinodh Sa
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ireneusz Kordal wrote:
Vinodh Sa wrote:
Ireneusz Kordal wrote:On oracle you can also track sessions using after logon and before logoff triggers.
Hi Ireneusz, Can you explain in a little brief about this ?


I show you a simple example.
These triggers are created at schema level (by user test):


Then we fire a little program in java that connects to and disconnects from oracle


and here is the result:


The last 21st login is because I logged as test with sqlplus - triggers are fired always, after each login and logoff.


edit
These triggers must be carefully tested, especially afterlogon trigger, because when error occurs this prevents user from login in.
In this case DBA must drop this trigger.


Hi Ireneusz, Thanks for your response. Will check the code and revert.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!