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 block
e.printStackTrace();
}finally{
dbutils.close(null, rs, conn,cs);
}
}
}