带有输出参数的存储过程
2015-08-08 23:36
375 查看
创建带有输出参数的存储过程:
以上代码即在当前数据库中创建了带有输出参数的存储过程,名字为proc_user_out,可调用此存储过程查询 userid=2 的 username。
在命令行中调用此存储过程代码:
在类中写如下关键代码调用此存储过程:
drop procedure if exists proc_user_out; delimiter // create procedure proc_user_out(out out_param varchar(20)) begin select username into out_param from user where userid=2; end // delimiter ;
以上代码即在当前数据库中创建了带有输出参数的存储过程,名字为proc_user_out,可调用此存储过程查询 userid=2 的 username。
在命令行中调用此存储过程代码:
call proc_user_out(@result); select @result;注意:以上的@result不能变
在类中写如下关键代码调用此存储过程:
public static void main(String[] args) { Connection con = null; CallableStatement cs = null; try { con = getConnection(); String sql = "{call proc_user_out(?)}"; cs = con.prepareCall(sql); cs.registerOutParameter(1, Types.VARCHAR); cs.execute(); String name = cs.getString(1); System.out.println(name); } catch (Exception e) { e.printStackTrace(); } }以上两种调用均可得到 userid=2 的 username 。
相关文章推荐
- 田忌赛马 南阳oj364 HDU杭电1052【贪心】
- 从外部引入整个工程到eclipse中后,工程前面出现小红叉
- 待重写
- JavaScript学习笔记——BOM_window子对象_History、Location、Screnn对象
- [leedcode 240] Search a 2D Matrix II
- 常用的linux内核双向链表API介绍
- HDU5353 Average
- hdu5366 The mook jong(动规或记忆化搜索)
- uva725除法uva11059最大乘积uva10976分数拆分(暴力求解法)
- 使用注解实现自定义junit(简)
- 这七种情况下,不要创业
- UE4发报机-Event_Assign事件
- 《C++编程思想》 第十一章 运算符重载 (原书代码+习题+解答)
- hadoop系列:zookeeper(1)——zookeeper单点和集群安装
- 第一百二十八天 how can i 坚持
- 让您的电脑在任意目录可以支持图片的粘贴,试试看呗(第二篇)~
- BestCoder Round #50 (div.1) ($)
- 算法、技术及其它
- Sequoiadb该如何选择合适的SQL引擎
- 机器学习算法中如何选取超参数:学习速率、正则项系数、minibatch size