- 浏览: 96246 次
文章分类
最新评论
-
jXee:
<div class="quote_title ...
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection -
lgs0626:
求源码,兄弟给共享下吧
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection
JPA 2.1 introduces APIs to call Stored Procedure. It has similar programming pattern as executing a common CRUD sql statement.
@NamedStoredProcedureQuery: defines details of the stored proc to call
@StoredProcedureParameter: defines IN/OUT parameters of the stored proc
StoredProcedureQuery: Interface used to control stored procedure query execution
For more example: http://www.baeldung.com/jpa-stored-procedures
@NamedStoredProcedureQuery: defines details of the stored proc to call
@StoredProcedureParameter: defines IN/OUT parameters of the stored proc
StoredProcedureQuery: Interface used to control stored procedure query execution
-- create a function CREATE OR REPLACE FUNCTION test1.process_upload(p1 text, p2 integer) RETURNS integer AS $$ DECLARE arow record; counter integer := 0; BEGIN FOR arow IN (SELECT * FROM test1.buffer_table) LOOP -- process this row counter = counter + 1; END LOOP; RETURN counter; END; $$ LANGUAGE plpgsql; -- test the function select test1.process_upload('jwang', 10);
import javax.persistence.*; import java.io.Serializable; import java.util.Date; @Entity @Table(name = "buffer_table", schema = "test1") @NamedStoredProcedureQueries({ @NamedStoredProcedureQuery( name="processUpload", // query name used in your app procedureName = "process_upload", // name of stored proc in db //resultClasses = {BufferTable.class}, parameters = { @StoredProcedureParameter(name="p1", type=String.class, mode=ParameterMode.IN), @StoredProcedureParameter(name="p2", type=Integer.class, mode=ParameterMode.IN) } ) }) public class BufferTable implements Serializable { @Id @Column(name="id") private Integer id; @Column(name="name") private String name; @Column(name="created") private Date created; @Column(name="department_name") private String departmentName; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public String getDepartmentName() { return departmentName; } public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } }
public int processUpload() { StoredProcedureQuery spQuery = em.createNamedStoredProcedureQuery("processUpload"); // use named param - positional param can be used as well. spQuery.setParameter("p1", "jwang"); spQuery.setParameter("p2", 10); List results = spQuery.getResultList(); Integer result = results.size() > 0 ? (Integer) results.get(0) : null; log.info("Result from executing stored proc: " + result); return result != null ? result.intValue() : 0; }
For more example: http://www.baeldung.com/jpa-stored-procedures
发表评论
-
ActiveMQ and Spring JMS Framework Message Loss
2019-06-28 07:15 29Java Message Service (JMS) prov ... -
how to proxy to k8s web console
2018-06-28 07:16 529### how to access k8s web conso ... -
Send response and then process - async processing
2017-10-12 09:35 508If your request processing take ... -
java 8 time api test
2017-08-29 05:40 437public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 436@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 314JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 305If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 969you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 757Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 751you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1340If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 994The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 621http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2633Servlet 3.0 provides new annota ... -
Why JSF2 @ViewScoped not working?
2012-12-03 06:55 1342javax.faces.bean.ViewScoped sai ... -
When to configure an XA datasource?
2012-11-16 12:58 1224If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 9841. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1299<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5583If you have millions of record ... -
why Oracle sequence not working with JPA entity ID?
2012-09-19 08:08 933Suppose you have an Oracle seq ...
相关推荐
存储过程(Stored Procedure)是一组为了完 成特定功能的 SQL 语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给 出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,...
Using Informatica Stored Procedure Transformation
学习使用存储过程(Stored Procedure),是ASP程序员的必须课之一。所有的大型数据库SPAN>都支持存储过程,比如Oracle、MS SQL等,(但MS Access不支持,不过,在Access里可以使用参数化的查询)
MySQL Stored Procedure Programming Advance Praise for MySQL Stored Procedure Programming Preface Objectives of This Book Structure of This Book What This Book Does Not Cover Conventions ...
mysql存储过程方面的圣经,以通俗的示例方法讲述mysql存储过程的深奥内容,In MySQL Stored Procedure Programming, they put that hard-won experience to good use. Packed with code examples and covering ...
sybase stored procedure
mysql stored procedure programming PDF version
The implementation of stored procedures in MySQL 5.0 ... This book, destined to be the bible of stored procedure development, is a resource that no real MySQL programmer can afford to do without.
TERADATA SQL Reference:UDF, UDM, and External Stored Procedure Programming
一个基于ADO.NET+COBOL+Stored Procedure的程序例子代码。
一个基于C#实现的后台运行 any stored procedure 的类库源码程序
SQL Server 2000 Stored Procedure Programming SQL SERVER 2000存储过程编程,英文版,pdf文件,6M左右,贼清晰
简单明了的教程,快速入门,强烈推荐。也是735认证考试的材料。
解决OracleRAC集群下创建SDE时报Stored procedures错误问题 环境:Oracle11.2.0.3 两节点RAC集群,windows server2008R2,FCSAN共享存储,ArcGIS Desktop 1031
A class to call stored procedures that do not return records调用存储过程的类
存储过程(Stored Procedure), 是一组为了完成特定功能的SQL 语句,集经编译后 存储在数据库中,用户通过指定存储过程的名字并给出参数,如果该存储过程带有参数来执行它, 在SQL Server 的系列版本中,存储过程...
A tool to generate class files to implement stored procedures创建类文件执行存储过程的工具
Oracle Database 11g Administration Workshop II (数据库管理-课堂练习II 学生指南第3册)
Bug with stored procedure parameters is fixed Bug with setting query parameters as a string is fixed PostgreSQL data provider Bug with stored procedure parameters is fixed SQLite data provider Bug ...
Bug with stored procedure parameters is fixed Bug with setting query parameters as a string is fixed PostgreSQL data provider Bug with stored procedure parameters is fixed SQLite data provider Bug ...