Java调用Oracle的过程和函数

2016-02-19 15:40 1 1 收藏

下面图老师小编要向大家介绍下Java调用Oracle的过程和函数,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - 编程语言 】

内容或简介:

/**

调用数据库里的一个函数

一个函数本质上一个返回一个结果的存储过程,这个例子示范了怎么调用有in、out和in/out参数的函数

***********************************/

CallableStatement cs;

try {

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

// 调用一个没有参数的函数; 函数返回 a VARCHAR

// 预处理callable语句

  cs = connection.prepareCall("{? = call myfunc}");

// 注册返回值类型

cs.registerOutParameter(1, i);

// Execute and retrieve the returned value

cs.execute();

String retValue = cs.getString(1);

// 调用有一个in参数的函数; the function returns a VARCHAR

cs = connection.prepareCall("{? = call myfuncin(?)}");

// Register the type of the return value

cs.registerOutParameter(1, Types.VARCHAR);

// Set the value for the IN parameter

cs.setString(2, "a string");

// Execute and retrieve the returned value

cs.execute();

retValue = cs.getString(1);

// 调用有一个out参数的函数; the function returns a VARCHAR

cs = connection.prepareCall("{? = call myfuncout(?)}");

// Register the types of the return value and OUT parameter

cs.registerOutParameter(1, Types.VARCHAR);

cs.registerOutParameter(2, Types.VARCHAR);

// Execute and retrieve the returned values

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

cs.execute();

retValue = cs.getString(1);           // return value

String outParam = cs.getString(2);    // OUT parameter

// 调用有一个in/out参数的函数; the function returns a VARCHAR

cs = connection.prepareCall("{? = call myfuncinout(?)}");

// Register the types of the return value and OUT parameter

cs.registerOutParameter(1, Types.VARCHAR);

cs.registerOutParameter(2, Types.VARCHAR);

// Set the value for the IN/OUT parameter

cs.setString(2, "a string");

// Execute and retrieve the returned values

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

cs.execute();

retValue = cs.getString(1);           // return value

outParam = cs.getString(2);           // IN/OUT parameter

} catch (SQLException e) {

}

来源:https://www.tulaoshi.com/n/20160219/1610146.html

延伸阅读
标签: SQLServer
  数学函数 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) S:select ceiling(-1.001) value O:select ceil(-1.001) value from dual 3.取整(小) S:select floor(-1.001) value O:select floor(-1.001) value from dual 4.取整(截取) S:s...
正在看的ORACLE教程是:oracle 函数。PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序。在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类:  单行函数  组函数  本文将讨论如何利用单行函数以及使用规则。 SQL中的单行函数 ...
SQLServer和Oracle是大家经常用到的数据库,在此感谢作者总结出这些常用函数以供大家参考。 数学函数 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) S:select ceiling(-1.001) value O:select ceil(-1.001) value from dual 3.取整(小) S:select floor(-1....
标签: SQLServer
1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) S:select ceiling(-1.001) value O:select ceil(-1.001) value from dual 3.取整(小) S:select floor(-1.001) value O:select floor(-1.001) value from dual 4.取整(截取) S:select cast(-1.002 as int) value O:select trunc(-1.002) value from du...
文中提及函数并非Oracle及SQL Server 的全部功能,尤其分析挖掘函数,并未完全涵盖,请以实际解决问题优先,勿妄谈二者优劣。 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) S:select ceiling(-1.001) value O:select ceil(-1.001) value from dual 3.取整(小) S:select...

经验教程

856

收藏

23
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部