Transactions between different databases in J2EE (continued)

Source: Internet
Author: User
Tags microsoft website
Another friend said that my previous article was too simple. In fact, I am actually a little lazy and unconsciously regard my blog as a journal account.
The following is a detailed description of the platform (windows2000 + sqlserver2000 + msjdbc + weblogic + eclipse + lomoz). The basic configuration is not described in this article. If you do not understand it, please google it.
Procedure:
1: First go to the Microsoft website and install the latest jdbc driver. To support distributed transactions, you need to do the following (in the help file): first copy SQLServer JTAsqljdbc under the msjdbc installation directory. dll to the inn directory under the sqlserver installation directory, then open the query analyzer and load SQLServer JTAinstjdbc under the msjdbc installation directory. SQL statement and execution (may need to be restarted)
2: Create two databases in sqlserver and create two tables respectively. Start the weblogic console and create two connection pools pointing to the first two databases respectively. Note that you should select the Microsoft jdbc driver of type 4xa, then create two data sources pointing to the connection pool.
3: OK. Now we can write a program. Create a war-type lomoz project in eclipse, and select weblogc as the server.
Create. jsp. Here we will describe that to use jta, you only need Context ctx = new InitialContext (htx); UserTransaction tx = (UserTransaction) ctx. lookup ("javax. transaction. userTransaction "); you can use tx. The following is. jsp example, but this example is different from the operation. If you want to successfully insert data to the two databases at the same time. rollback () to tx. commit.
A. The jsp code is as follows:
<% @ Page language = "java" import = "java. SQL. *, java. util. *, javax. naming. *, javax. transaction. *" %>
<! Doctype html public "-// w3c // dtd html 4.0 transitional // en">
<Html>
<Head>
<Title> Lomboz JSP </title>
</Head>
<Body bgcolor = "# FFFFFF">
<%
Context ctx = null;
Hashtable htx = new Hashtable ();
UserTransaction tx = null;
Htx. put (Context. INITIAL_CONTEXT_FACTORY, "weblogic. jndi. WLInitialContextFactory ");
Htx. put (Context. PROVIDER_URL, "t3: // localhost: 7001 ");
Connection conn = null;
Statement stmt = null;
Javax. SQL. DataSource ds = null;
Connection connx = null;
Statement stctx = null;
Javax. SQL. DataSource dsx = null;
Try {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.