Search Engine: Elastic

Article ID: 3336, created on Nov 30, 2007, last review on May 6, 2014

  • Applies to:
  • H-Sphere


There are two possible types of connections to the H-Sphere database:

In any case, you should use only prepared stataments when working with the H-Sphere database!


Regular Shared Connections

The part of the code which establishes and uses a regular database connection should look something similar to this:

        PreparedStatement ps = null;
        Connection con = Session.getDb();
        try {
            ps = con.prepareStatement(...........);
        } finally {


Connections With Opened Transaction

In general, the part of the code which establishes and uses a transaction connection should look as follows:

        // checking if the transaction exists
        boolean wasTrans = Session.isTransConnection();
           Connection con = wasTrans ? Session.getDb() : Session.getTransConnection();
           try {
           // some operation with the database
           } catch (Exception ex){
        if (!wasTrans) {
        // rollback transaction
        // here should also be some data to release cache and to synchronize with old data in HS DB
        throw ex;
           } finally {
        if (!wasTrans) {
        // commit transaction and release connection
        } else {


  1. There is the pool of transaction connections (5 by default). Opening a new transaction that exceeds this maximum would cause the system to hang up.

  2. As the number of available transactions is resctricted, you must release the transaction connection you have opened by using the following command:

  3. To get an opened transaction connection:

            con = Session.getTransConnection();

    Later in the code, you may get the same connection:

            con = Session.getDb();

    Never close a transaction connection you haven't opened!

  4. Please make sure you synchronize your objects with the corresponding data in the database. You must release your cache if you make a rollback.

f213b9fa8759d57bee5d547445806fe7 3ef1f5f998c0dc182718a7fe4376f875

Email subscription for changes to this article
Save as PDF