<% set_title(product_name, "JTA Transaction Example") %>

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

An example code fragment shows how to run a JTA global transaction using <%=vars.product_name%> as the JTA transaction manager.

The external data sources used in this transaction are configured in the `cache.xml` file. See [Configuring Database Connections Using JNDI](configuring_db_connections_using_JNDI.html#topic_A5E3A67C808D48C08E1F0DC167C5C494) for a configuration example.

``` pre
Region r = ...; // the  region data source 
ds = ...; // other data source    

  try  {     
         Context ctx = cache.getJNDIContext();      
         Connection conn =  null;
         UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");     
         tx.begin();
         conn = ds.getConnection();
         Statement stmt = conn.createStatement();
         String sqlSTR =  "insert into " + tableName + " values (........ )";
         stmt.executeUpdate(sqlSTR);   
         r.put("key", "value");
         stmt.close();     
         tx.commit();
         conn.close();
   } catch (NamingException e) { 
         // handle the exception   
   }
```


