How do I make my Java application identify itself to Oracle on connection?(如何让我的 Java 应用程序在连接时向 Oracle 标识自己?)
问题描述
当我的应用程序连接到 Oracle 数据库时,我希望能够通过查看它所连接的数据库中的活动会话来查看.目前它将自己标识为JDBC 瘦客户端",因为这是我正在使用的驱动程序,但我拥有的其他基于 Java 的应用程序能够以某种方式将此值设置为更有意义的值,例如SQL Developer".我认为它是 Connection 或 OracleDataSource 的一个属性,但我还没有找到一个可以解决问题的方法.这可能吗?以防万一,我使用的是 Java 1.5、Oracle 10g 和 10g 瘦驱动程序.
When my application connects to an Oracle database I want to be able to see by looking at the active sessions in the database that it is connected. Currently it identifies itself as "JDBC Thin Client" because that's the driver that I'm using, but other Java based applications that I have are somehow able to set this value to something more meaningful, like "SQL Developer". I thought it was a property of the Connection or the OracleDataSource, but I've not managed to find one that does the trick. Is this possible? In case it matters, I'm using Java 1.5, with Oracle 10g and the 10g thin driver.
推荐答案
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
在应用程序级别,您可以使用以下方法在 v$session 中设置 client_info、module 和 action>:
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
这篇关于如何让我的 Java 应用程序在连接时向 Oracle 标识自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让我的 Java 应用程序在连接时向 Oracle 标识自己?
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
