Hi,

I am sorry if this is a trivial question, but I was unable to find an
answer in OJB documentation or other Internet sources.

I need to run a plain SQL Update inside a PersistenceBroker
transaction. The DBMS is Oracle 8.

My solution is:
//--------------------------------------------------------------------------
        PersistenceBroker broker = null;
        try {
            
            broker = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
            broker.beginTransaction();
            StringBuffer commandBuffer = new StringBuffer();
            
            commandBuffer.append("update some_table ");
            commandBuffer.append("set some_field = ? ");
            
            Connection conn = null;
            PreparedStatement command = null;

            int rows;
        
            try {
              conn = broker.serviceConnectionManager().getConnection();
              command = conn.prepareStatement(commandBuffer.toString());
              rows = command.executeUpdate();
            } finally {
              if(command != null){
                  command.close();
              }
            }

          //--- Make some queries and updates using Persistent broker here
          //...
          broker.commitTransaction();
        } catch (LookupException e) {
            if(broker != null){
                broker.abortTransaction();
            }
            throw new PersistenceBrokerException(e);
        } catch (SQLException e) {
            if(broker != null){
                broker.abortTransaction();
            }
            throw e;
        }finally{
            
            if(broker != null){
                broker.serviceConnectionManager().releaseConnection();
                broker.close();
            }
        }
//--------------------------------------------------------------------------

This code is working, but I don't know if there are any problems
related to getting the connection directly from
serviceConnectionManager.

I will apreciate any comments-

Wilson

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to