连载三:模拟JavaEye论坛首页存储过程



 

 

我使用的PLsql 由于没有使用LOOP  CURSOR  所以  java 代码会比较多  以后在发布 一个新版本

 

 

DELIMITER $$

DROP PROCEDURE IF EXISTS `anywhere`.`setp2`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `setp2`
(IN v_category_id INT,OUT v_category_name VARCHAR(20),OUT v_latest_theme_aboutoneCategory VARCHAR(20),OUT v_theme_num_aboutoneCategory INT)
    BEGIN
       select name into  v_category_name from category where id=v_category_id;
       select title into v_latest_theme_aboutoneCategory from theme where theme.id = (select max(id) from theme where theme.category_id=v_category_id);
       select count(*) into v_theme_num_aboutoneCategory from theme where theme.category_id=v_category_id  ; 
    END$$

DELIMITER ;
 

 

public static void test2() throws SQLException{
		
	    Connection con = JDBCUtil.getConnection();
	    
	    PreparedStatement ps = con.prepareStatement("select id from category ");
	    ResultSet rs = ps.executeQuery();
	    CallableStatement call =null;
	    while(rs.next()){
	    	int id = rs.getInt(1);
	    	call = con.prepareCall("{call setp2(?,?,?,?)}");
	    	call.setInt(1, id);
	    	call.registerOutParameter(2,Types.VARCHAR);
	    	call.registerOutParameter(3, Types.VARCHAR);
	    	call.registerOutParameter(4, Types.INTEGER);
	    	
	    	call.execute();
	    	
	
	    	System.out.println(call.getString(3));
	    	
	    	
	    }call.close();
		con.close();
		
	}
  • 连载三:模拟JavaEye论坛首页存储过程_第1张图片
  • 大小: 19.7 KB
  • 连载三:模拟JavaEye论坛首页存储过程_第2张图片
  • 大小: 2 KB
  • 查看图片附件

你可能感兴趣的:(连载三:模拟JavaEye论坛首页存储过程)