for(int i = 0; i<head.size();i++){
cell=row.createCell((short)i);
XSSFRichTextString rts=new XSSFRichTextString((String)head.get(i));
cell.setCellValue(rts.toString());
}
rs.executeSql();
int counts =rs.getCounts();
long sTime =System.currentTimeMillis();
int i= 0;
String datas ="";
while(rs.next()){
for(int rowindex=0; rowindex<counts;rowindex++){
row=sheet.createRow(rowindex+1);
for(int cellindex=0;cellindex<head.size();cellindex++){
cell=row.createCell((short)cellindex);
datas=rs.getString(cellindex);
System.out.println(datas);
XSSFRichTextString richString = new XSSFRichTextString(datas == null ? "" :datas);
cell.setCellValue(richString.toString());
}
}
}
第一个for循环是输出的标题,while循环是填充值, rs.executeSql();
有值!!而且很多,但是我输出出来只有第一行数据循环了很多次,求大家看看是怎么回事
编号 姓名 部门 员工状态
0 男0 上海0 学生0
0 男0 上海0 学生0
0 男0 上海0 学生0
0 男0 上海0 学生0
0 男0 上海0 学生0
运行出来是这种效果
示列代码:
int rowindex=0;
while(rs.next()){
row=sheet.createRow(++rowindex);
for(int cellindex=0;cellindex<head.size();cellindex++){
cell=row.createCell((short)cellindex);
datas=rs.getString(cellindex);
XSSFRichTextString richString = new XSSFRichTextString(datas == null ? "" :datas);
cell.setCellValue(richString.toString());
}
}
运行出来的效果是只输出了第一行,剩下的值没有填充进去
追答在while循环上面定义一个就行了,关键看你的标题在第几行。已经发了代码了,还有问题的话你DEBUG一下就能看出问题的。
int rowindex=0;
while(rs.next()){//检查while循环是否只循环了一次。
row=sheet.createRow(++rowindex);
检查while循环是否只循环了一次。
while循环执行了很多次,输出的结果还是第一个数据显示了很多次
追答一。检查SQL查询出来的值是否和导出的值一样。
二。如果一样,确定问题是sql,如果不一样,暂时认为不可能会有这种情况
能帮我把代码改一下吗?谢谢了