Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > make rollback() and throw a exception

Reply
Thread Tools

make rollback() and throw a exception

 
 
ojvm
Guest
Posts: n/a
 
      07-12-2005
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.

 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      07-13-2005
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"


 
Reply With Quote
 
 
 
 
enrique
Guest
Posts: n/a
 
      07-13-2005
catch it in the class and throw it again (or throw a different
exception)

 
Reply With Quote
 
ojvm
Guest
Posts: n/a
 
      07-15-2005
ok, this is other good thing i'll try they both. thanks for your answer.

 
Reply With Quote
 
ojvm
Guest
Posts: n/a
 
      07-15-2005
yes, it is what i was thinking. throw a different exception

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To throw or to throw not? Emanuele D'Arrigo Python 6 11-15-2008 04:12 PM
java: make (xslt) transformer throw exception on error killy971 XML 1 08-06-2008 08:27 AM
exception throw and handle and resume Rahul C++ 4 12-08-2007 08:23 PM
JNI's throw new does not throw an exception yarona@m-sys.com Java 15 09-08-2005 08:36 AM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM



Advertisments