| Author |
Custom JDBC connection listener
|
Vinodh Sa
Ranch Hand
Joined: May 06, 2010
Posts: 55
|
|
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
|
Thanks, Vinodh
[Servlet tutorial]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Vinodh Sa
Ranch Hand
Joined: May 06, 2010
Posts: 55
|
|
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
Joined: Jun 21, 2008
Posts: 423
|
|
|
On oracle you can also track sessions using after logon and before logoff triggers.
|
 |
Vinodh Sa
Ranch Hand
Joined: May 06, 2010
Posts: 55
|
|
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
Joined: Jun 21, 2008
Posts: 423
|
|
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
Joined: May 06, 2010
Posts: 55
|
|
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.
|
 |
 |
|
|
subject: Custom JDBC connection listener
|
|
|