jdbc - stored procedure isn't get executed -


i need help. have jdbc code calls oracle stored procedure. class has code:

public class daoimpl {      private string sql = "{call main.sp_calc(?,?,?,?,?)}";     private connection conn = null;      public daoimpl(connection conn) {         this.conn = conn;                 }      @override     public synchronized void executesp(string year, string month, long id) throws sqlexception {        try (callablestatement cs = conn.preparecall(sql);) {            cs.setobject(1, id);            cs.setobject(2, year);            cs.setobject(3, month);            cs.setobject(4, 0);            cs.registeroutparameter(5, types.integer);            cs.execute();        }     }  } 

i have 2 clients class, javase tester class , stateless ejb. javase main() method have code:

      try {             drivermanager.registerdriver(new oracledriver());             connection conn = drivermanager.getconnection(db_url, user, pass);             daoimpl dao = new daoimpl(conn);                         dao.executesp("2015", "02", 99561010l);         } catch (sqlexception ex) {             logger.getlogger(sptester.class.getname()).log(level.severe, null, ex);         } 

the stateless ejb has other code:

        try {                          conn = ds.getconnection();             dao dao = daoimpl(conn);                             dao.executesp("2015", "02", 99561010l);                         } catch (sqlexception ex) {             throw new sqlexception(ex);         } {                             conn.close();         } 

ds instance variable injected ejb datasource comes jdbc connection pool declared in glassfish of type oracle.jdbc.xa.client.oraclexadatasource. variables db_url, user, pass of javase programm, have same values use jdbc connection pool

as you'll notice, difference connection object. both javase , ejb use ojdbc6.jar driver. both uses java 1.7.0_u2, that's why use try-with-resources.

the problem javase works! both of them returns after seconds of processing javase programm works. have tried many things.. cmt , bmt ejb, wrapped , unwrapped types of id, synchronize , unsynchronize method, etc. need code working in ejb :(

what's wrong ejb?

thanks in advance

this cmt version of ejb

@stateless @localbean @interceptors({propagatesessioncontextinterceptor.class}) public class calcbean extends basecontextsessionbean {  @resource(mappedname = "jdbc/maestro") protected datasource ds; public connection conn = null;  public void executesp(string year, string month, long id) throws sqlexception {     try {         conn = ds.getconnection();         dao dao = daoimpl(conn);          dao.executesp("2015", "02", 99561010l);                                      } catch (sqlexception ex) {         throw new sqlexception(ex);     } {                         conn.close();     }    }  } 

this bmt version of ejb

@stateless @localbean @interceptors({propagatesessioncontextinterceptor.class}) @transactionmanagement(transactionmanagementtype.bean) public class calcbean extends basecontextsessionbean {  @resource(mappedname = "jdbc/maestro") protected datasource ds; public connection conn = null;  @resource usertransaction tx;   public void executesp(string year, string month, long id) throws sqlexception {    try {        try {             tx.begin();             conn = ds.getconnection();             dao dao = daoimpl(conn);              dao.executesp("2015", "02", 99561010l);                              tx.commit();         } catch (sqlexception ex) {             throw new sqlexception(ex);         } {                             conn.close();         }    } catch (exception e) {        throw new ejbexception(e);    }    }  }  public class basecontextsessionbean {   @resource  public sessioncontext ctx;  }  public class propagatesessioncontextinterceptor {    @aroundinvoke   public object myinterceptor(invocationcontext ctx) throws exception   {    basecontextsessionbean sb = (basecontextsessionbean)ctx.gettarget();    controllistener.setsessioncontext(sb.ctx);    object o = ctx.proceed();    return o;   }  }  public interface dao {     public void executesp(string year, string month, long id) throws sqlexception; } 

i don't know reason of basecontextsessionbean , propagatesessioncontextinterceptor. originally, ejb used useless jdbc framework (that uses classes), replaced daoimpl class. use dao interface decouple implementation, daoimpl been execute (in ejb, daoimpl implements dao, forgot put in earlier post)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -