!--a11y-->
Combining JDO and JDBC 
In certain scenarios you might need to combine the use of JDO and JDBC with a single database connection. Although there is no specific API for this, with the integration of the SAP JDO implementation into the J2EE Engine you can obtain the same database connection and use it with both JDO and JDBC within a single transaction.

Note that this scenario only works when you use the same database connection for both JDO and JDBC, as described below. You cannot use two different connections and combine them in a distributed transaction.
To get the same database connection, you must look up the default DataSource using the alias SAP/BC_JDO. This is the alias used by the default PersistenceManagerFactory to get a database connection. Then you must call the getConnection() method of the DataSource in the same transaction where you call the JDO PersistenceManager. The underlying resource management mechanism provides the same connection, which is used by the PersistenceManager. After completing the transaction, close the resources that were used.

Context ctx = new InitialContext(); PersistenceManagerFactory pmf = (PersistenceManagerFactory) ctx.lookup( "java:comp/env/jdo/defaultPMF"); DataSource ds = (DataSource) ctx.lookup("java:comp/env/SAP/BC_JDO");
UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction"); try { ut.begin();
pm = pmf.getPersistenceManager();
// work with JDO ...
conn = ds.getConnection();
// work with JDBC ...
ut.commit(); } catch (Exception e) { ut.rollback(); } finally { conn.close(); pm.close(); } |

To perform the lookup operations as shown in the sample above, you must add resource references for both the PMF and the DataSource in the deployment descriptor of your Web component or enterprise bean.
