关于JSP调用存储过程的问题(菜鸟求教) 现有存储过程 sp_EmpAdd @a int,@b varchar(20),@c int ……在JSP页面调用这个存储过程怎么写啊?注意,参数是不定的,可能没有,也可能有1个、2个,存储过程都可以执行。现在在JSP中怎么去调用啊。。高手指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 随便搜索一下就可以找到答案了: 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);} 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 请问设置参数时setstring(1, poetname);1可不可以用参数名称代替?这个1是指该参数在存取过程中的位置还是在set_death_age(?, ?)中?号的位子?小弟一个项目刚刚接触JAVA,还请多多指教啊 请求算法思路 JSP与JAVA基础 hibernate提交事务问题 在java中如何在Date对象的基础上加15分钟? 如何清空文件里面的内容 请问JSF里如何 获得 buttonCommand的标签 请问Crystal Report Design 10 for java 下载地址!谢谢! 请问各位 ,能否帮助参谋参谋 ,作java的,作企业应用有前途还是作在线游戏有前途呢? struts提供的例子程序(注册、登陆、保存邮箱地址的那个)??? JBoss CMP数据源错误! j2ee中奇怪的乱吗问题(中文+数字 正常 )( 数字+中文 中文部分乱码) 有关Jsp中session的菜鸟问题
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);
}
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
1可不可以用参数名称代替?
这个1是指该参数在存取过程中的位置还是在set_death_age(?, ?)中?号的位子?小弟一个项目刚刚接触JAVA,还请多多指教啊