更改 Oracle JDBC 瘦客户端标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1612657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:16:26  来源:igfitidea点击:

Change Oracle JDBC Thin Client Identifier

oraclejdbc

提问by JeeBee

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.

当连接到 Oracle 时,JDBC 驱动程序将自己标识为 Oracle 的“JDBC 瘦客户端”(在 v$session 中为“程序”)。v$session 中还有一个 'ClientInfo' 列可能用于此目的,但它始终为空。

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

我们需要识别连接到 Oracle 的不同应用程序(它们运行在同一台主机上,所以 v$session 中的 'machine' 列都是一样的),那么是否可以更改 Oracle JDBC Thin Client 驱动程序的识别方式本身(例如,我们可以输入应用程序名称)?

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.

或者是否有推荐的方法来做到这一点?一个限制是我们在 Struts 中为某些应用程序执行此操作,这些应用程序在内部处理连接设置。

回答by Rob van Laarhoven

[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, moduleand actionin v$session:

在应用程序级别,您可以使用以下方法在v$session 中设置client_info模块操作

dbms_application_info.set_client_info
dbms_application_info.set_module
dbms_application_info.set_action

回答by JeeBee

There is also an Oracle function:

还有一个Oracle函数:

dbms_application_info.set_client_info('Client Info'); 

which sets the ClientInfo column in v$session.

它在 v$session 中设置 ClientInfo 列。