现有存储过程 sp_EmpAdd @a int,@b varchar(20),@c int ……
在JSP页面调用这个存储过程怎么写啊?
注意,参数是不定的,可能没有,也可能有1个、2个,存储过程都可以执行。
现在在JSP中怎么去调用啊。。高手指教

解决方案 »

  1.   

    随便搜索一下就可以找到答案了: http://czqhh.bloghome.cn/posts/38543.html至于说"参数是不定的,可能没有",用Java判断一下就行了:
    String st = null;
    if (conditionA) {//根据条件设置参数数量
       st = "{call MyProc(?,?,?)}";
    }else{
       st = "{call MyProc(?,?)}";
    }callsta=con.prepareCall(st);if (conditionA) {{//根据条件设置参数
       callsta.setInt(1,10248);
       callsta.registerOutParameter(2,Types.VARCHAR);
       callsta.registerOutParameter(3,Types.INTEGER);
    }else{
       callsta.setInt(1,10248);
       callsta.registerOutParameter(2,Types.VARCHAR);
    }
      

  2.   

    try{
    int age = 39;string poetname = "dylan thomas";callablestatement proc = connection.preparecall("{ call set_death_age(?, ?) }");proc.setstring(1, poetname);proc.setint(2, age);cs.execute();}catch (sqlexception e){ // ....} create procedure set_death_age(poet varchar2, poet_age number)poet_id number;begin select id into poet_id from poets where name = poet;insert into deaths (mort_id, age) values (poet_id, poet_age);end set_death_age; public static void setdeathage(poet dyingbard, int age) throws sqlexception{connection con = null;callablestatement proc = null;try {con = connectionpool.getconnection();proc = con.preparecall("{ call set_death_age(?, ?) }");proc.setstring(1, dyingbard.getname());proc.setint(2, age);proc.execute();}finally {try { proc.close(); }catch (sqlexception e) {}con.close();}} 出处-http://www.z6688.com/info/34931-1.htm
      

  3.   

    请问设置参数时setstring(1, poetname);
    1可不可以用参数名称代替?
    这个1是指该参数在存取过程中的位置还是在set_death_age(?, ?)中?号的位子?小弟一个项目刚刚接触JAVA,还请多多指教啊