Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Oracle JDBC Thin Client Identifier

Tags:

oracle

jdbc

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.

like image 473
JeeBee Avatar asked Oct 23 '09 10:10

JeeBee


2 Answers

[Identical to this answer]

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);

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 the following methods to set client_info, module and action in v$session:

dbms_application_info.set_client_info
dbms_application_info.set_module
dbms_application_info.set_action
like image 121
Rob van Laarhoven Avatar answered Oct 17 '22 09:10

Rob van Laarhoven


There is also an Oracle function:

dbms_application_info.set_client_info('Client Info'); 

which sets the ClientInfo column in v$session.

like image 45
JeeBee Avatar answered Oct 17 '22 09:10

JeeBee