在 JDBC for Oracle 中设置客户端信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2876956/
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 20:40:05  来源:igfitidea点击:

setting Client Info in JDBC for Oracle

javaoraclejdbcdriver

提问by Alvaro Castro

I have a Java application which needs to be audited (so obviously I need a way in which the app can be identified with the application name). I googled and found that ojdbc14 has the method .setClientInfowhich allows registering the application with a customized name, so I am trying to get it work but I get the following error:

我有一个需要审核的 Java 应用程序(所以显然我需要一种可以用应用程序名称识别应用程序的方法)。我用谷歌搜索并发现 ojdbc14 具有.setClientInfo允许使用自定义名称注册应用程序的方法,所以我试图让它工作但我收到以下错误:

Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.setClientInfo(Ljava/lang/String;Ljava/lang/String;)V

线程“main”中的异常 java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.setClientInfo(Ljava/lang/String;Ljava/lang/String;)V

I am using ojdbc14 with oracle 10g express. If I do not set the line:

我正在将 ojdbc14 与 oracle 10g express 一起使用。如果我不设置该行:

connection.setClientInfo("ApplicationName","Customers");

it works pretty well ....and by checking the audit info I can see that oracle gets the application name:OS_program_name=JDBC Thin Client, but I need a way to change it for a customized name.

它工作得很好......通过检查审计信息,我可以看到 oracle 获取应用程序名称:OS_program_name=JDBC Thin Client,但我需要一种方法来更改它以获得自定义名称。

By uncommenting that line which is supposed to set the application name it returns the error above.

通过取消注释应该设置应用程序名称的那一行,它会返回上面的错误。

Per oracle documentation that method is available for a Connectionobject. Do you have any idea how to solve this issue?

根据 oracle 文档,该方法可用于Connection对象。你知道如何解决这个问题吗?

回答by gokhant

For AbstractMethodError, please check Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?

对于 AbstractMethodError,请检查为什么在尝试在数据库中加载 blob 时会出现 java.lang.AbstractMethodError?

In order to distinguish your connections in Oracle you can use this sample code below:

为了区分您在 Oracle 中的连接,您可以使用以下示例代码:

Properties jdbcProperties = new Properties();

this.jdbcProperties.put("user", userName);
this.jdbcProperties.put("password", password);
this.jdbcProperties.put("v$session.program", "YourApplicationName");
DriverManager.getConnection(url, jdbcProperties);

then check v$session by grouping against program column for your connections..

然后通过针对您的连接的程序列进行分组来检查 v$session..