tags:

views:

957

answers:

2

When connecting to Oracle the JDBC driver identifies itself as "JDBC Thin Client" to Oracle (in v$session as the 'program'). There is also a 'ClientInfo' column in v$session that might be used for this, but it's always empty.

We have a need to identify different applications connecting to Oracle (which are running on the same host, so the 'machine' column in v$session is all the same), so is it possible to change how the Oracle JDBC Thin Client driver identifies itself (so we could put the application name in, for example)?

Or is there a recommended way to do this? One restriction is that we're doing this within Struts for some of the applications, which is handling the connection setup internally.

+2  A: 

Identical to

java.util.Properties props = new java.util.Properties();
props.setProperty("password","mypassword");
props.setProperty("user","myusername");
props.put("v$session.osuser", System.getProperty("user.name").toString());
props.put("v$session.machine", InetAddress.getLocalHost().getCanonicalHostName());
props.put("v$session.program", "My Program Name");
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
Connection conn=
DriverManager.getConnection("jdbc:oracle:thin:@myhostname:1521:mysid",props);

query v$session

SQL>select username,osuser,program,machine
from v$session
where username = 'ROB'; 

USERNAME  OSUSER       PROGRAM             MACHINE
--------- -----------  ------------------  -----------
ROB       rmerkw       My Program Name     machine

At application level you can use dbms_application_info.set_module and dbms_application_info.set_client_info to set clientinfo,module,action in v$session

Robert Merkwürdigeliebe
Cheers, that should help for some of the applications - does this work with a OracleConnectionPoolDataSource? I see there's a setConnectionProperties method there. Do I have to specify all the fields listed, even if I'm using the .setUser(), .setPassword(), etc, methods on OracleConnectionPoolDataSource?
JeeBee
I know it works on a OracleConnectionPoolDataSource. It's long ago so I don't remember the specifics. setConnectionProperties takes a java.util.Properties as an argument. Don't think this empties the user and password set earlier with .setUser(), .setPassword(). Do I make sense ? ;-)
Robert Merkwürdigeliebe
Hi! Yes, that makes sense, and it works with just the v$session.program set. Cheers.
JeeBee
A: 

There is also an Oracle function:

dbms_application_info.set_client_info('Client Info');

which sets the ClientInfo column in v$session.

JeeBee