存储过程
来源:互联网 发布:5118的子域名查询工具 编辑:程序博客网 时间:2024/06/05 23:59
存储过程
1.在数据库中使用存储过程(存储过程的创建DBA)
#无参的存储过程delimiter $$ create procedure pro1() begin select * from stu ; end ; $$#带输入参数的存储过程 create procedure pro2(in a int) begin select * from stu where id = a ; end ; $$delimiter $$create procedure pro3(in a int,in b int)begin select a + b ;end ;$$delimiter ;delimiter $$create procedure pro4(in n int)begin select * from t3 where id = n ;end ;$$delimiter ;#创建带输出参数的存储过程 delimiter $$ create procedure pro5(in a int,out b varchar(20)) begin select name into b from stu where id = a ; end ; $$call pro5(1,@n) ;select @n ;#创建带多个输出参数的存储过程 delimiter $$ create procedure pro6(in a int,out b varchar(20),out c int) begin select name,age into b,c from stu where id = a ; end ; $$select @name,@age $$
2.在JDBC中调用存储过程
package com.heima.jdbc;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.Types;import org.junit.Test;import com.heima.utils.JdbcUtils;//演示JDBC调用存储过程public class ProcedureTest {//执行不带返回值的存储过程没有任何任意@Testpublic void testPro2() throws Exception {// 获得链接对象Connection conn = JdbcUtils.getConnection();// 创建执行存储过程的命令对象CallableStatement cstmt = conn.prepareCall("{call pro2(?)}") ;//指定?的值cstmt.setInt(1, 1) ;//执行存储过程cstmt.execute() ;// 释放资源JdbcUtils.release(null, cstmt, conn);}@Testpublic void testPro5() throws Exception {// 获得链接对象Connection conn = JdbcUtils.getConnection();// 创建执行存储过程的命令对象CallableStatement cstmt = conn.prepareCall("{call pro5(?,?)}") ;//指定?的值cstmt.setInt(1, 1) ;//指定第二个?是输出参数cstmt.registerOutParameter(2, Types.VARCHAR) ;//执行存储过程cstmt.execute() ;//获得返回值String name = cstmt.getString(2) ;System.out.println(name);// 释放资源JdbcUtils.release(null, cstmt, conn);}}
0 0
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- 存储过程
- bat-2
- android在手机桌面弹出一个提醒activity,finish掉后。从任务管理器进去还是这个提醒activity
- 在安卓DDMS中找相册文件夹传一张图片
- nil Nil NSnull sok svk
- SAPUI5 (07) - MVC文件的名称和位置
- 存储过程
- java根据IP获取用户所在地
- 求助: fragment 下listview.setOnItemClickListener() 无效
- Android利用JSBridge与HTML5的交互使用
- 分辨率,dpi,dp,与最终显示大小的四角关系
- 2016-个人总结
- 欢迎使用CSDN-markdown编辑器
- php 调用imagemagick实现老照片效果
- 写在2016的尾巴上