jdbc 存储过程

来源:互联网 发布:linux copy命令不覆盖 编辑:程序博客网 时间:2024/05/22 13:19
package com.fill.jweb_jdbc_new;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Types;import com.mysql.jdbc.CallableStatement;import com.mysql.jdbc.Connection;public class jdbcccgc {public static void main(String[] args) {// TODO Auto-generated method stub}public static void callProcedure(){Connection conn=null;String sql="{call javaProcDemo(?,?)}";CallableStatement cs=null;ResultSet rs=null;try {conn=dbutils.getConnection();cs=(CallableStatement) conn.prepareCall(sql);cs.setString(1, "态度");cs.registerOutParameter(2, Types.VARCHAR);//注册第二个参数为输出参数boolean b=cs.execute();//执行System.out.println(cs.getString(2));//获取存储过程的返回结果if(b){rs=cs.getResultSet();while(rs.next()){int id=rs.getInt(1);String name=rs.getString(2);}//获取更多的结果集b=cs.getMoreResults();}//获取返回参数} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{dbutils.close(null, rs, conn,cs);}}}