如何获得给定数据源的给定连接是 xa 还是非 xa?
How to get given connection is xa or non xa for given data source?
使用此代码我无法获得连接是 xa 或非 xa
DatabaseMetaData dbmd = con.getMetaData();
dbmd.getDriverName();
System.out.println("DriverName - "+dbmd.getDriverName()+"DriverName class - "+dbmd.getDriverName().getClass() +"DriverName class name - "+ dbmd.getDriverName().getClass().getName());
System.out.println("DriverVersion - "+dbmd.getDriverVersion());
System.out.println("MultipleTransactions - "+dbmd.supportsMultipleTransactions());
System.out.println("Transactions - "+dbmd.supportsTransactions());
System.out.println("getClassgetName - "+dbmd.getClass().getName());
System.out.println("CLASSNAME"+(dbmd.getDriverName()).getClass().getName());
System.out.println("url - "+dbmd.getURL()+" getUserName "+dbmd.getUserName());
System.out.println("DefaultTransactionIsolation - "+dbmd.getDefaultTransactionIsolation()+" Connection "+dbmd.getConnection()+" Connection class "+dbmd.getConnection().getClass()+" Connection class name "+dbmd.getConnection().getClass().getName());
你的问题标题是 "given a datasource"。您有权访问 DataSource object 吗?您的代码示例仅表明您有权访问连接。
假设您可以访问数据源 object,您可以简单地执行以下操作:
if(myDataSource instanceof javax.sql.XADataSource)
System.out.println("XA datasource");
else{
try{
myDataSource.unwrap(javax.sql.XADataSource.class);
System.out.println("XA datasource");
} catch(SQLException sqle){
System.out.println("Not an XA datasource");
}
}
使用此代码我无法获得连接是 xa 或非 xa
DatabaseMetaData dbmd = con.getMetaData();
dbmd.getDriverName();
System.out.println("DriverName - "+dbmd.getDriverName()+"DriverName class - "+dbmd.getDriverName().getClass() +"DriverName class name - "+ dbmd.getDriverName().getClass().getName());
System.out.println("DriverVersion - "+dbmd.getDriverVersion());
System.out.println("MultipleTransactions - "+dbmd.supportsMultipleTransactions());
System.out.println("Transactions - "+dbmd.supportsTransactions());
System.out.println("getClassgetName - "+dbmd.getClass().getName());
System.out.println("CLASSNAME"+(dbmd.getDriverName()).getClass().getName());
System.out.println("url - "+dbmd.getURL()+" getUserName "+dbmd.getUserName());
System.out.println("DefaultTransactionIsolation - "+dbmd.getDefaultTransactionIsolation()+" Connection "+dbmd.getConnection()+" Connection class "+dbmd.getConnection().getClass()+" Connection class name "+dbmd.getConnection().getClass().getName());
你的问题标题是 "given a datasource"。您有权访问 DataSource object 吗?您的代码示例仅表明您有权访问连接。
假设您可以访问数据源 object,您可以简单地执行以下操作:
if(myDataSource instanceof javax.sql.XADataSource)
System.out.println("XA datasource");
else{
try{
myDataSource.unwrap(javax.sql.XADataSource.class);
System.out.println("XA datasource");
} catch(SQLException sqle){
System.out.println("Not an XA datasource");
}
}