如何在没有 WSConnection 的情况下设置客户端信息
How to set client information without WSConnection
我们的项目使用Websphere,我们必须使用WSConnection设置"client information"。 DB2 数据库使用这些进行审计。这在 Websphere 中运行良好。但是,我们现在想在 websphere 之外的控制台应用程序 运行 中使用相同的代码库。所以我想将下面的代码更改为与 websphere 无关。
是否有更标准的方法来完成以下操作?直接使用 jdbc 的东西?或者其他一些方法,让我不创建从此代码到 websphere 及其库的依赖关系?
Properties props = new Properties();
props.setProperty(WSConnection.CLIENT_ID, userid);
props.setProperty(WSConnection.CLIENT_APPLICATION_NAME, bpcode);
if (connection instanceof WSConnection) {
WSConnection wconn = (WSConnection) connection;
wconn.setClientInformation(props);
} else {
log.error("Connection was NOT an instance of WSConnection so client ID and app could not be set");
}
是的,在JDBC中添加了用于设置客户端信息的标准接口。
您可以使用 connection.setClientInfo(name, value)、
分别设置每个 属性
或者,您可以通过 connection.setClientInfo(properties)
一次性设置
要确定您的驱动程序支持的确切客户端信息集 属性 名称,请使用 databaseMetaData.getClientInfoProperties() 方法。
我们的项目使用Websphere,我们必须使用WSConnection设置"client information"。 DB2 数据库使用这些进行审计。这在 Websphere 中运行良好。但是,我们现在想在 websphere 之外的控制台应用程序 运行 中使用相同的代码库。所以我想将下面的代码更改为与 websphere 无关。
是否有更标准的方法来完成以下操作?直接使用 jdbc 的东西?或者其他一些方法,让我不创建从此代码到 websphere 及其库的依赖关系?
Properties props = new Properties();
props.setProperty(WSConnection.CLIENT_ID, userid);
props.setProperty(WSConnection.CLIENT_APPLICATION_NAME, bpcode);
if (connection instanceof WSConnection) {
WSConnection wconn = (WSConnection) connection;
wconn.setClientInformation(props);
} else {
log.error("Connection was NOT an instance of WSConnection so client ID and app could not be set");
}
是的,在JDBC中添加了用于设置客户端信息的标准接口。
您可以使用 connection.setClientInfo(name, value)、
分别设置每个 属性或者,您可以通过 connection.setClientInfo(properties)
一次性设置要确定您的驱动程序支持的确切客户端信息集 属性 名称,请使用 databaseMetaData.getClientInfoProperties() 方法。