- 浏览: 99992 次
文章分类
最新评论
-
jXee:
lgs0626 写道求源码,兄弟给共享下吧 "jee ...
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 567### how to access k8s web conso ... -
Send response and then process - async processing
2017-10-12 09:35 558If your request processing take ... -
java 8 time api test
2017-08-29 05:40 480public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 479@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 362JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 338If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 1013you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 811Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 780you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1399If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 1038The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 674http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2696Servlet 3.0 provides new annota ... -
Why JSF2 @ViewScoped not working?
2012-12-03 06:55 1371javax.faces.bean.ViewScoped sai ... -
When to configure an XA datasource?
2012-11-16 12:58 1265If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 10481. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1337<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5624If you have millions of record ... -
why Oracle sequence not working with JPA entity ID?
2012-09-19 08:08 971Suppose you have an Oracle seq ...
相关推荐
**标题详解:** "hibernate-jpa-2.1-api 1.0.0.Final API" 这个标题指的是Hibernate对Java Persistence API (JPA) 2.1规范的实现,版本为1.0.0.Final。Hibernate是Java领域中最受欢迎的对象关系映射(ORM)框架之一...
### 存储过程(Stored Procedure)详解 #### 一、存储过程的概念与作用 存储过程是一种预先编写并编译好的SQL语句集合,通常用于实现特定的数据库操作或逻辑处理。存储过程存储在数据库服务器中,用户可以通过指定...
### 学习使用存储过程(Stored Procedure) 在IT领域中,存储过程(Stored Procedure)是一项重要的技术,尤其对于从事Web开发尤其是ASP编程的开发者来说,掌握如何使用存储过程至关重要。存储过程是一种预先编译并...
在数据集成领域,Informatica是一个强大的企业级ETL(提取、转换、加载)工具,而“使用Informatica存储过程转换”是它的一项重要功能。存储过程转换允许用户通过Informatica执行预先在数据库中构建的存储过程,从而...
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 ...
Stored Procedure是SQL Server数据库中预编译的SQL语句集合,它可以执行一系列复杂的数据库操作,如查询、插入、更新和删除数据。使用Stored Procedure有诸多优点,包括提高性能、减少网络流量、增强安全性以及提供...
mysql存储过程方面的圣经,以通俗的示例方法讲述mysql存储过程的深奥内容,In MySQL Stored Procedure Programming, they put that hard-won experience to good use. Packed with code examples and covering ...
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.
标题中的“一个基于C#实现的后台运行 any stored procedure 的类库源码程序”表明这是一个C#编程项目,它的核心功能是能够在后台执行SQL Server的存储过程(stored procedure)。存储过程是预编译的SQL语句集合,...
在 Sybase 中,存储过程分为两种类型:用户定义的存储过程(User-Defined Stored Procedures)和系统存储过程(System Stored Procedures)。用户定义的存储过程是由开发者创建的,可以根据业务需求进行定制。系统...
涉及的关键字包括CREATE PROCEDURE、CALL、ALTER PROCEDURE、DROP PROCEDURE等。 3. 参数和变量:学习存储过程中的输入参数、输出参数以及局部变量的使用和声明。参数允许存储过程接收外部的输入值,而局部变量则...
DB2存储过程是数据库管理中的一个重要概念,它是一组为了完成特定功能的SQL语句集,可以在数据库中预先编译并存储。这个教程是专为初学者设计的,旨在帮助快速掌握DB2存储过程的创建、调用以及相关概念。...
在Oracle RAC(Real Application Clusters)环境下,安装和配置ArcGIS Desktop的SDE(Spatial Database Extensions)数据库连接时,可能会遇到"Stored procedures"错误。这个问题通常与Oracle RAC的特性有关,即其...
标题中的"A tool to generate class files to implement stored procedure"指的是一个软件工具,它的主要功能是自动生成Java类文件,这些类文件被设计用来实现数据库中的存储过程。存储过程是在数据库中预编译的SQL...
2. **准备SQL命令**:对于不返回记录的存储过程,SQL命令通常是`CALL procedure_name()`。类中可能包含一个方法用于设置这个命令,可能接受存储过程名称作为参数。 3. **执行存储过程**:使用数据库连接对象执行SQL...
存储过程(Stored Procedure), 是一组为了完成特定功能的SQL 语句,集经编译后 存储在数据库中,用户通过指定存储过程的名字并给出参数,如果该存储过程带有参数来执行它, 在SQL Server 的系列版本中,存储过程...
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 ...