java调用存储过程

http://www.qqread.com/java/2008/05/w408958.html

测试

 create procedure selectCommentCount(in ids int,out res int)
 begin
   select count(id) into res from newsComment where newsid=ids;
 end

命令行测试‘
set @ids=1;
call selectCommentCount(@ids,@a);
select @a; 
显示1
 
public static void main(String[] args) throws SQLException {
		Connection conn=JdbcUtil1.getConnection();
		conn.setAutoCommit(false);
			
		CallableStatement cs=conn.prepareCall("call selectCommentCount(?,?)");
		
		cs.setInt(1, 1);
//		cs.registerOutParameter(2, 10);
		cs.execute();
		
		System.out.println(cs.getInt(2));
		
	}
 

你可能感兴趣的:(java,html)