Hibernate调用存储过程和函数
操作大批量数据或复杂逻辑,考虑到执行效率和代码量的时候,存储过程和函数在数据库中是预编译好的,调用执行效率高
// 调用过程 {call 过程名称(?,?,?)}
public static void test1() throws Exception {
Connection connection = request.getSession().connection();
String sql = "{call addmethod(?,?,?)}";
CallableStatement call = connection.prepareCall(sql);
// 设置输入参数
call.setInt(1, 3);
call.setInt(2, 7);
// 设置输出参数
call.registerOutParameter(3, Types.INTEGER);
call.execute();
int ans = call.getInt(3);
System.out.println(ans);
}
// 调用函数{?= call 函数名称(?,?)}
public static void test3() throws Exception {
Connection connection = request.getSession().getConnection();
String sql = "{?= call addmethod1(?,?)}";
CallableStatement call = connection.prepareCall(sql);
// 设置输入参数
call.setInt(2, 3);
call.setInt(3, 7);
// 设置返回值
call.registerOutParameter(1, Types.INTEGER);
call.execute();
int ans = call.getInt(1);
System.out.println(ans);
}
oracle存储过程
create or replace procedure addmethod(n1 in number,n2 in number,ans out number) as
begin
select n1 + n2 into ans from dual;
end;
oracle函数
create or replace function addmethod1(n1 number,n2 number,ans out number)
Result number;
begin
select n1 + n2 into ans from dual;
return ans;
end;
Hibernate调用存储过程和函数的更多相关文章
- 转:EF调用存储过程、函数
EF调用存储过程.函数 2014-04-02 09:12:20| 分类: ORM框架|举报|字号 订阅 一.ef4.1 codeFirst 修改表结构 增加字段等 EF code ...
- JDBC(13)—JDBC调用存储过程和函数
步骤: JDBC调用存储过程和函数 步骤: ①:通过Connection对象的prepareCall()方法创建一个CallableStatement对象的实例,在使用Connection对象的pre ...
- MySQL学习笔记:调用存储过程或函数报1418错误
问题 MySQL开启bin-log后,调用存储过程或者函数以及触发器时,会出现错误号为1418的错误: ERROR 1418 (HY000): This function has none of DE ...
- jdbc调用存储过程和函数
1.调用存储过程 public class CallOracleProc { public static void main(String[] args) throws Exception{ Stri ...
- [原创]java WEB学习笔记79:Hibernate学习之路--- 四种对象的状态,session核心方法:save()方法,persist()方法,get() 和 load() 方法,update()方法,saveOrUpdate() 方法,merge() 方法,delete() 方法,evict(),hibernate 调用存储过程,hibernate 与 触发器协同工作
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- java调用存储过程和函数
以对表test进行增,删,改,查进行说明:1.新建表test create table TEST ( TID NUMBER not null, TNAME VARCHAR2(32), TCODE VA ...
- 【转】java调用存储过程和函数
一.概述 如果想要执行存储过程,我们应该使用 CallableStatement 接口. CallableStatement 接口继承自PreparedStatement 接口.所以CallableS ...
- JDBC第二篇--【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】
这是我JDBC的第一篇 http://blog.csdn.net/hon_3y/article/details/53535798 1.PreparedStatement对象 PreparedState ...
- JDBC【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】
1.PreparedStatement对象 PreparedStatement对象继承Statement对象,它比Statement对象更强大,使用起来更简单 Statement对象编译SQL语句时, ...
随机推荐
- javase基础笔记1——简介和发展
软件分为 系统软件 windows linux类 (unix)mac(麦金塔).数据库管理系统 unix linux 开源os(open source) 免费 开放 free os operation ...
- 使用android ProgressBar和Toast生成一个界面
首先我需要这样一个界面 这个界面是在使用AudioManager.adjustStreamVolume(int streamType, int direction, int flags)显示出来的,记 ...
- Ubuntu14 搭载vim环境查看源码
首先是下载完整的vim74,然后编译安装.遗憾的是当编译时,没有开启图形界面. 在安装新版本的Vim之前,你需要卸载原来安装的老版本Vim,依次在终端下执行下列命令: sudo apt-get rem ...
- JMeter监控Linux服务器资源案例
JMeter是一款压力测试工具,我们也可以用它来监控服务器资源使用情况.JMeter正常自带可以通过Tomcat的/manager/status来监控服务资源使用情况.这种情况只能监控Tomcat支持 ...
- loadrunner生成随机身份证和银行卡号
生成银行卡号码: Action() { char card[19] = {'6','2','2','7','0','0','0','0','0','0','0','0','0','0','0','0' ...
- JQ学习(二)
jQuery 效果 jQuery hide() 和 show() 语法: $(selector).hide(speed,callback); $(selector).show(speed,callba ...
- express-3 最佳实践
版本控制 版本控制有以下益处: 文档: 能够回溯项目的历史,回顾所做的决策及组件的开发顺序,可形成宝贵的文档.记录项目的历史是十分有价值的. 归属: 团队工作,分工清晰,节省沟通成本. 试验: 你可以 ...
- 【wpf】Path画扇形以及Path的Data属性的理解
<Path x:Name="PathFillColor" Fill="{TemplateBinding Property=Button.Background}&qu ...
- linux tomcat配置https
自己生成一个ssl证书,因为是自己生成的所以该证书,不被浏览器信任(具体表现https前面有个X) [root@centos apache-tomcat-]# keytool -genkey -ali ...
- UVa1515 Pool construction(最小割)
题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...