db2界面调用存储过程_DB2数据库调用存储过程的方法及实例

import java.net.URL;

import java.sql.*;

class test2

{publicstatic void main(Stringargs[])

{Stringurl="jdbc:db2://wellhope/sample";Stringuser="db2admin";Stringpassword="db2admin";

try

{

Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();//与数据库建立连接

Connection con=DriverManager.getConnection(url,user,password);

checkForWarning(con.getWarnings());

DatabaseMetaData dma=con.getMetaData();Stringstr="This is a string";//inthashcode=str.hashCode();//System.out.println("Hashcode"+hashcode);//创建Statement对象,用于执行SQL语句

Statement stmt=con.createStatement();//创建CallableStatement对象,用于执行存储过程

CallableStatement cs=con.prepareCall("{call PRO_YHDL1(?,?,?)}");//注册输出参数

cs.registerOutParameter (3, Types.INTEGER);intresult=0;

cs.setString(1,"123");

cs.setString(2,"123");

cs.execute();

result=cs.getInt (3);

dispResultSet(result);

cs.close();

con.close();

}

catch(SQLException ex)

{

System.out.println("* * * SQLException caught * * *");while(ex!=null)

{

System.out.println("SQLState:"+ex.getSQLState());

System.out.println("Message:"+ex.getMessage());

System.out.println("Vendor:"+ex.getErrorCode());

exex=ex.getNextException();

System.out.println("");

}

}

catch(java.lang.Exception ex)

{

ex.printStackTrace();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值