Dear friends,
I have written a BMP bean. I am using UserTransaction to do my transaction.
I am getting a message after ut.commit() that transaction successfully
committed.
But when I check the database nothing is inserted there..
I am using JBoss-3.0. My code is
package twophase;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.transaction.UserTransaction;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
public class TwoPhaseBean implements SessionBean
{
public boolean doTransaction(String id,String name,String balance){
try{
InitialContext IC = new InitialContext();
UserTransaction ut =
(UserTransaction)javax.rmi.PortableRemoteObject.narrow(IC.lookup("java:comp/
UserTransaction"),javax.transaction.UserTransaction.class);
System.out.println("Got the UserTransaction::"+ut.toString());
DataSource ds =
(DataSource)javax.rmi.PortableRemoteObject.narrow(IC.lookup("java:OracleDS")
,javax.sql.DataSource.class);
System.out.println("Got the Datasource::"+ds.toString());
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ut.begin();
System.out.println("insert into bank values
('"+id+"','"+name+"','"+balance+"')");
int status = stmt.executeUpdate("insert into bank values
('"+id+"','"+name+"','"+balance+"')");
if(status != 0){
ut.commit();
System.out.println("Successfully commited");
}else{
ut.rollback();
System.out.println("Transaction Rolledback");
}
if(con !=null){
con.close();
}
return true;
}
catch(Exception ee){
System.out.println("Server Exception:"+ee.getMessage());
ee.printStackTrace();
return false;
}
}
public void ejbCreate(){}
public void ejbPostCreate(){}
public void ejbRemove(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void setSessionContext(SessionContext sc){}
}
What am I missing here ...? Can any one please point me out...
Regards
Yogaraj
"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this
communication is strictly Prohibited.
If you have received this message by error, please notify us
immediately, return the original mail to the sender and delete the
message from your system."
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".