日期:2014-05-18  浏览次数:20681 次

Jsp中ResultSet问题求教!(在线等答案)
ResultSet   rs=stmt.executeQuery( "select   count(*)   form   form1   where   name= ' "+age[i]+ " ' ");
我想查询不同年龄人的个数,要是直接在sql语句中写出具体年龄将会有很多条ResultSet语句,而每个ResultSet都要给它取一个不同的名字,否则就会报错,这要是在年龄个数未知的情况下就更难以实现。
我设想用一个字符串数组来作为ResultSet的名字:
String[]   rs_name=new   String[i]     //i为事先查出的不同的年龄的个数
for(int   j=0;j <i;j++){
      ResultSet   rs_name[j]=stmt.executeQuery( "select   count(*)   form   form1   where   name= ' "+age[j]+ " ' ");
}
结果总是报错:rs_name[i]处少一个],不知道我这种方法是否可行,如果可行的话具体语句怎么写呢?如果不可行,那要怎样实现我所描述的功能呢?
请各位高手不吝赐教!感激不尽!


------解决方案--------------------
String[] rs_name=new String[i] ???
-------------------------------
ResultSet[] rs_name=new ResultSet[i];
------解决方案--------------------
为何不用GROUP BY?
select name, count(*) form form1 group by name order by name