查询操作、存储过程、函数调用中使用行处理器-bboss persistent框架行处理器使用-1
2008-12-18 10:01
417 查看
查询操作、存储过程、函数调用中使用行处理器-bboss persistent框架行处理器使用-1
存储过程中使用行处理器-RowHandle接口,自己管理和处理out参数。下面的示例是将存储过程test_p的out参数通过行处理器处理后再设置到java对象Test_p中,应用程序得到的将是经过行处理器处理过的java对象。
存储过程定义如下:
CREATE OR REPLACE PROCEDURE test_p(id in number,
name out varchar2
,name1 out varchar2,test out number
,nomatch out number) IS
/******************************************************************************
NAME: test
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2008-10-27 1. Created this procedure.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: test
Sysdate: 2008-10-27
Date and Time: 2008-10-27, 17:05:33, and 2008-10-27 17:05:33
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)
******************************************************************************/
BEGIN
--tmpVar := 0;
name := 'hello name';
name1 := 'hello name1';
test := id;
--insert into test(id,name) values(SEQ_TEST.nextval,'name1');
commit;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END test_p;
/
java对象Test_p:
public class Test_p {
private String test;
private String name;
private String name1;
private int count = 0;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String toString()
{
return new StringBuffer().append("name=").append(name).append(",name1=").append(name1).append(",test=").append(test).toString();
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
行处理器的处理过程如下:
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
//不允许的操作: Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class,new RowHandler(){
public void handleRow(Object rowValue, Record record) {
Test_p test_p = (Test_p)rowValue;
try {
test_p.setTest(record.getString("test")+"天马");
test_p.setName1(record.getString("name1"));
test_p.setName(record.getString("name"));
} catch (SQLException e) {
e.printStackTrace();
}
}
});
System.out.println("Test_p is " + tets);
}
catch(Exception e)
{
e.printStackTrace();
}
代码相当简单。
bboss项目下载列表 在sourceforge访问地址为: https://sourceforge.net/project/showfiles.php?group_id=238653
存储过程中使用行处理器-RowHandle接口,自己管理和处理out参数。下面的示例是将存储过程test_p的out参数通过行处理器处理后再设置到java对象Test_p中,应用程序得到的将是经过行处理器处理过的java对象。
存储过程定义如下:
CREATE OR REPLACE PROCEDURE test_p(id in number,
name out varchar2
,name1 out varchar2,test out number
,nomatch out number) IS
/******************************************************************************
NAME: test
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2008-10-27 1. Created this procedure.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: test
Sysdate: 2008-10-27
Date and Time: 2008-10-27, 17:05:33, and 2008-10-27 17:05:33
Username: (set in TOAD Options, Procedure Editor)
Table Name: (set in the "New PL/SQL Object" dialog)
******************************************************************************/
BEGIN
--tmpVar := 0;
name := 'hello name';
name1 := 'hello name1';
test := id;
--insert into test(id,name) values(SEQ_TEST.nextval,'name1');
commit;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END test_p;
/
java对象Test_p:
public class Test_p {
private String test;
private String name;
private String name1;
private int count = 0;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String toString()
{
return new StringBuffer().append("name=").append(name).append(",name1=").append(name1).append(",test=").append(test).toString();
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
行处理器的处理过程如下:
CallableDBUtil callableDBUtil = new CallableDBUtil();
try
{
callableDBUtil.prepareCallable("{call test_p(?,?,?,?)}");
//不允许的操作: Ordinal binding and Named binding cannot be combined!
callableDBUtil.setInt("id", 10);
callableDBUtil.registerOutParameter("name", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("name1", java.sql.Types.VARCHAR);
callableDBUtil.registerOutParameter("test", java.sql.Types.INTEGER);
Test_p tets = (Test_p)callableDBUtil.executeCallableForObject(Test_p.class,new RowHandler(){
public void handleRow(Object rowValue, Record record) {
Test_p test_p = (Test_p)rowValue;
try {
test_p.setTest(record.getString("test")+"天马");
test_p.setName1(record.getString("name1"));
test_p.setName(record.getString("name"));
} catch (SQLException e) {
e.printStackTrace();
}
}
});
System.out.println("Test_p is " + tets);
}
catch(Exception e)
{
e.printStackTrace();
}
代码相当简单。
bboss项目下载列表 在sourceforge访问地址为: https://sourceforge.net/project/showfiles.php?group_id=238653
相关文章推荐
- 查询操作、存储过程、函数调用中使用行处理器-bboss persistent框架行处理器使用
- MySQL使用集合函数进行查询操作实例详解
- 使用ODAC调用ORACLE的自定义函数和存储过程
- Hibernate-Criteria查询(3)DetachedCriteria构造查询条件、命名查询、原生SQL、调用存储过程(使用JDBC)
- 使用C#调用存储过程,用函数合理组织代码,使程序更加的清晰(示例)
- 使用Npgsql库调用PostgreSQL的函数(存储过程)
- SQL2000系统表、存储过程、函数的功能介绍及应用2009年01月21日 星期三 11:38虽然使用系统存储过程、系统函数与信息架构视图已经可以为我们提供了相当丰富的元数据信息,但是对于某些特殊的元数据信息,我们仍然需要直接对系统表进行查询。因为SQL
- Oracle-oracleSQL对单表各种查询操作及函数的使用
- T-SQL操作语句之数据查询(二):查询中使用函数
- 使用Npgsql库调用PostgreSQL的函数(存储过程)
- 查询某个表被哪些存储过程(以下简称 SP)使用到、查找那些过程对该表做了更新操作:
- 数据库操作sqlserver查询哪些存储过程使用了某个表
- 一对一关联查询时使用relation连贯操作查询后,调用getLastSql()方法输出的sql语句
- pymongo 查询排序操作(参数与函数调用查询对比)
- 今日收获总结(关于存储过程时间查询的一些方法以及字段截取的函数及调用示例)
- 使用C#调用存储过程,用函数合理组织代码,使程序更加的清晰(示例)
- Access2003中使用 无限分类 模块函数,可用在查询中 类似SQL的存储过程
- 批处理,变量,逻辑控制,函数,高级查询(含存储过程)的SQL SERVER 高级操作
- 使用纯C函数指针调用C++的类成员函…
- ASP.Net中使用VB.Net调用存储过程并得到返回值