1

我的问题是我在 jboss 部署文件夹中配置了一个 oracle-ds.xml。我可以得到dataSource和connection的实例。现在,我想通过 jboss api 从数据库配置中获取密码。此刻我能做什么?

数据库配置:

<datasources>
  <xa-datasource>
    <jndi-name>XPCDataSource</jndi-name>
    <track-connection-by-tx/>
    <isSameRM-override-value>false</isSameRM-override-value>
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    <xa-datasource-property name="URL">jdbc:oracle:thin:@172.17.16.49:1521:ora49</xa-datasource-property>
    <xa-datasource-property name="User">workbench_0628</xa-datasource-property>
    <xa-datasource-property name="Password">workbench_0628</xa-datasource-property>
    <min-pool-size>10</min-pool-size>
    <max-pool-size>50</max-pool-size>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
    <no-tx-separate-pools/>
    <metadata>
      <type-mapping>Oracle9i</type-mapping>
    </metadata>
  </xa-datasource>
  <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter" name="jboss.jca:service=OracleXAExceptionFormatter">
    <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
  </mbean>
</datasources>
4

1 回答 1

0

你有没有尝试过这样的事情?

   Connection conn = myJBossDatasource.getConnection();
   WrappedConnection wrappedConn = (WrappedConnection)conn;
   Connection underlyingConn = wrappedConn.getUnderlyingConnection();
   OracleConnection oracleConn = (OracleConnection)underlyingConn;

我主要使用 BEA/Oracle(Weblogic),但很久以前就这样做了……如果您查看 OracleConnection 对象,它有一些常量:

   CONNECTION_PROPERTY_PASSWORD
   CONNECTION_PROPERTY_USER_NAME
  • 参见:http ://docs.oracle.com/cd/E18283_01/appdev.112/e13995/oracle/jdbc/OracleConnection.html (JavaDoc)
于 2012-07-16T03:47:47.617 回答