Java 在运行时更改WebSphere数据源架构

Java 在运行时更改WebSphere数据源架构,java,jdbc,db2,websphere,database-schema,Java,Jdbc,Db2,Websphere,Database Schema,是否可以在运行时更改WebSphere数据源的默认模式 例如,我将以下jndi配置为: <jee:jndi-lookup id="dataSource" jndi-name="jdbc/test" lookup-on-startup="true" resource-ref="true" /> 但是,当应用程序启动并调用dataSource.getConnection().getSchema() 在我的包装器类的getConnection()中 调试getConnection()方法

是否可以在运行时更改WebSphere数据源的默认模式

例如,我将以下jndi配置为:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/test" lookup-on-startup="true" resource-ref="true" />
但是,当应用程序启动并调用
dataSource.getConnection().getSchema()
在我的包装器类的getConnection()中

调试getConnection()方法时,dataSource是一个com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource对象


不管怎样,我能完成我在这里要做的事情吗?我希望能够在运行时更改调用getConnection()时的模式值。

SQLFeatureNotSupportedException将在JDBC驱动程序或WebSphere Application Server级别(或两者)不支持JDBC 4.1时引发。如果使用WebSphereApplicationServerLiberty,您将希望启用jdbc-4.1或jdbc-4.2功能,而不是jdbc-4.0。如果使用WebSphereApplicationServerTraditional,您将需要确保您使用的是JDBC4.1(或更高版本)支持的最新版本。在这两种情况下,通过调用connection.getMetaData().getjdbcmayorversion和connection.getMetaData().getjdbcminorvision,检查您的JDBC驱动程序是否符合JDBC 4.1或更高版本。此外,唯一支持JDBC 4.1的WebSphere application server传统版本是version 9.1。我们只有8.5.5。我想这是行不通的。不,您将无法在8.5.5上使用JDBC4.1Get/SetSchema方法。但是,根据您使用的数据库,您可能能够使用SQL查询来获取和设置模式,这将允许您执行基本相同的操作。
<resource-ref name="jdbc/test" binding-name="jdbc/test" id="TEST_db"/>
<resource-ref name="jdbc/test" connection-management-policy="DEFAULT" isolation-level="TRANSACTION_READ_COMMITTED" id="TEST_db"/>
<bean id="schemaAwareDataSource" class="com.util.SchemaAwareDataSource" >
    <property name="dataSource" ref="dataSource" />
    <property name="schemaValue" value="${modifiableSchema}" />
</bean>
public class SchemaAwareDataSource implements DataSource {

     private DataSource dataSource;
     private String schemaValue;

     @Override
     public Connection getConnection() throws SQLException {

         if(dataSource.getConnection().getSchema().equals(schemaValue)) {
             return dataSource.getConnection();
         }

         dataSource.getConnection().setSchema(schemaValue);
         return dataSource.getConnection();     
     }

     //other implemented methods not shown
}