make rollback() and throw a exception

Discussion in 'Java' started by ojvm, Jul 13, 2005.

  1. ojvm

    ojvm Guest

    hi to everybody. tanks in advance for take some of your time to read
    this.


    ok the cuestion is simple. a class makes a transaction and throw a
    exception (SQLException) so, in jsp i make a instance of that class,
    because the class throws a exception it must be catch in the jsp.
    The problem is when a exception occurs in the class if i catch the
    exception in the same class in the jsp i can't see the error, so how
    can i make a rollback in the class and still see the error en the
    page??

    ok this is how it works

    ---jsp----

    try{
    MyClass c = new MyClass();
    }catch(SQLException e){
    out.println("error number..." + e.getErrorCode());
    }

    --class--
    //cn is a valid Connection;
    try{
    cn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
    cn.setAutoCommit(false);

    make some code...

    cn.commit();
    }catch(SQLException e){
    //if a error occurs make the rollback()
    cn.rollback();
    }

    with this code the error stays here, in this class.

    i hope someone can help me.
     
    ojvm, Jul 13, 2005
    #1
    1. Advertising

  2. On Tue, 12 Jul 2005 16:11:41 -0700, ojvm wrote:


    > //cn is a valid Connection;
    > try{
    > cn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
    > cn.setAutoCommit(false);
    >
    > make some code...
    >
    > cn.commit();
    > }catch(SQLException e){
    > //if a error occurs make the rollback()
    > cn.rollback();


    throw e;
    > }


    --
    You can't run away forever,
    But there's nothing wrong with getting a good head start.
    --- Jim Steinman, "Rock and Roll Dreams Come Through"
     
    Stefan Schulz, Jul 13, 2005
    #2
    1. Advertising

  3. ojvm

    enrique Guest

    catch it in the class and throw it again (or throw a different
    exception)
     
    enrique, Jul 13, 2005
    #3
  4. ojvm

    ojvm Guest

    ok, this is other good thing i'll try they both. thanks for your answer.
     
    ojvm, Jul 15, 2005
    #4
  5. ojvm

    ojvm Guest

    yes, it is what i was thinking. throw a different exception
     
    ojvm, Jul 15, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerri
    Replies:
    2
    Views:
    13,087
    Kevin Spencer
    Oct 27, 2003
  2. Replies:
    15
    Views:
    7,700
    Roedy Green
    Sep 8, 2005
  3. Rahul
    Replies:
    4
    Views:
    270
    terminator
    Dec 8, 2007
  4. killy971
    Replies:
    1
    Views:
    706
    Johannes Koch
    Aug 6, 2008
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    340
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page