2010年12月16日星期四

java中调用mysql存储过程

 

有参数的情况

CallableStatement cstmt=conn.prepareCall("{call hasContest(?)}");
cstmt.registerOutParameter(1, Types.BOOLEAN);
cstmt.execute();
boolean b=cstmt.getBoolean(1);

 

无参数的情况

CallableStatement cstmt=conn.prepareCall("{call hasContest}");
ResultSet rs=cstmt.executeQuery();
rs.next();
return rs.getBoolean(1);

 

给定的数据库用户必须具有执行的权限,同时在数据的url中要添加参数,如下所示

jdbc:mysql://10.28.79.2:3306/cbbt?noAccessToProcedureBodies=true

没有评论:

发表评论