package poceduretest;
import java.sql.*;
class MainTest
{
public static void main(String[] args)
{
java.sql.Connection con = ConnectionManager.getConnection(); //先获得连接
/**
* 基本存储过程调用
*/
try
{
java.sql.CallableStatement cs = con.prepareCall("{call sp_num}"); //传入的参数是call 和 存储过程名
cs.execute();
if(cs.execute())
{
}else
{
java.sql.ResultSet r = cs.getResultSet();
// 输出记录集里的数据
while (r.next())
{
System.out.print(r.getString(1));
System.out.print("\t" + r.getString(2));
System.out.print("\t" + r.getInt(3));
System.out.println("\t" + r.getInt(4));
}
}
}
catch (SQLException ex)
{
}
/**
* 调用有参数的存储过程1
*/
try
{
int x = 15;
java.sql.CallableStatement cs = con.prepareCall("{call sp_num1(?)}"); //此内的?与存储过程里的输出和输入参数一致
cs.setInt(1, x);
// 执行存储过程
cs.execute();
java.sql.ResultSet r = cs.getResultSet();
// 输出记录集里的数据
while (r.next())
{
System.out.print(r.getString(1));
System.out.println("\t" + r.getString(2));
}
}
catch (SQLException ex)
{
}
/**
* 调用有参数的存储过程2
*/
try
{
String name = "business";
java.sql.CallableStatement cs = con.prepareCall("{call sp_num2(?)}");
cs.setString(1, name);
// 执行存储过程
cs.execute();
java.sql.ResultSet r = cs.getResultSet();
// 输出记录集里的数据
while (r.next())
{
System.out.print(r.getString(1));
System.out.println("\t" + r.getString(2));
}
}
catch (SQLException ex)
{
}
/**
* 带有输出参数的存储过程
*/
try
{
String name = "business";
java.sql.CallableStatement cs = con.prepareCall("{call sp_num5(?,?)}");
cs.registerOutParameter(1, java.sql.Types.INTEGER);
cs.setInt(2, 5);
cs.execute();
System.out.println(cs.getInt(1));
}
catch (SQLException ex)
{
}
/**
* 返回多个结果集的存储过程
*/
try
{
java.sql.CallableStatement cs = con.prepareCall("{call sp_num6}");
cs.execute();
do
{
java.sql.ResultSet t = cs.getResultSet();
while (t.next())
{
System.out.print(t.getString(1));
System.out.println("\t" +t.getString(2));
}
}while(cs.getMoreResults());
}
catch (SQLException ex)
{
}
}
}
java储存过程 java如何使用存储过程
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
qt opencv mat灰度转RGB
背景最近在学OpenCL,用的书是《OpenCL异构并行编程实战》。怎么说呢,感觉这本书比较迷,讲的很乱,跟着看完的话可能学不到什么。好在之前学过CUDA,勉强能够理解并行计算的思路。因此这里写了一下用显卡进行RGB2Gray的程序,也算是自己能够使用OpenCL进行一些简单的显卡计算吧。平台:Ubuntu18.04 + CUDA10.0 + MX150 + OpenCL 1.2 目
qt opencv mat灰度转RGB char 转 int char 转int char*转int char转int