![]() |
![]() |
Using the JTS Driver
Overview
Implementing with the JTS Driver
Overview
The Java Transaction Services or JTS driver is a server-side Java Database Connectivity (JDBC) driver that provides access to both connection pools and SQL transactions from applications running in WebLogic Server. Connections to a database are made from a connection pool and use a two-tier JDBC driver running in WebLogic Server to connect to the Database Management System (DBMS) on behalf of your application.
Once a transaction is begun, all of the database operations in a execute thread that get their connection from the same connection pool will share the same connection from that pool. These operations may be made through services such as Enterprise JavaBeans (EJB), or Java Messaging Service (JMS), or by directly sending SQL statements using standard JDBC calls. All of these operations will share the same connection and participate in the same transaction.When the transaction is committed or rolled back, the connection will be returned to the pool.
Although Java clients may not register the JTS driver themselves, they may participate in transactions via Remote Method Invocation (RMI). You can begin a transaction in a thread on a client and then have the client call a remote RMI object. The database operations executed by the remote object will become part of the transaction that was begun on the client. When the remote object is returned back to the calling client, you can then commit or roll back the transaction. The database operations executed by the remote objects must all use the same connection pool to be part of the same transaction.
Implementing with the JTS Driver
To use the JTS driver, you must have defined a database connection pool in WebLogic Server. For information on creating connection pools, see Creating and Using Connection Pools.
For this explanation we assume the connection pool is named "myConnectionPool." This explanation demonstrates creating and using a JTS transaction from a server-side application.
import javax.transaction.UserTransaction;
import java.sql.*;
import javax.naming.*;
import java.util.*;
import weblogic.jndi.*;
Context ctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext(env);
UserTransaction tx = (UserTransaction)
ctx.lookup("javax.transaction.UserTransaction");
tx.begin();
Driver myDriver = (Driver)
Class.forName("weblogic.jdbc.jts.Driver").newInstance();
Properties props = new Properties();
conn = myDriver.connect("jdbc:weblogic:jts:myConnectionPool", null);
If the additional database operations using the JTS driver use a different connection pool than the one specified in step 5., an exception will be thrown when you try to commit or rollback the transaction.
conn.close();
tx.commit();
// or:
tx.rollback();
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|