ssh2 下载问题
我用的是SSH2 现在有两个头疼的问题,网页上有两个功能 第一个是把数据库表下载成Excel,第二,就是分页
如果我的数据库用的是SQLServer2005 能下载但是不能query.setFirstResult(start);query.setMaxResults(number);这个的分页语句,用的话就报错。可是,下载可以用的。
如果用MySQL可以分页也能用query.setFirstResult(start);query.setMaxResults(number);不用报错,但是下载不能用。已经一个星期了,我怎么都搞不出来,很郁闷,请大虾来帮帮我,谢谢您们了。
这个是下载成Excel的类,用着没有问题。
public InputStream getInputStream() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("编号");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("所在部门");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("性别");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("出生日期");
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学历");
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学位");
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("现职称");
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("取得现职称日期");
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("专业名称");
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("必修(已通过)");
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("选修(总分)");
cell = row.createCell((short) 12);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("申核状态");
List<Teacher> list = this.listTeacher();
for (int i = 0; i < list.size(); i++) {
Teacher teacher = list.get(i);
row = sheet.createRow(i + 1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(i + 1);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getDepartment());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getName());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getSex());
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell
.setCellValue(teacher.getBirthday().toString().substring(0,
10));
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getDegree());
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getEducation());
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getPost());
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell
.setCellValue(teacher.getPosttime().toString().substring(0,
10));
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getProfressional());
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getCompulsoryresult());
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getEletiveresult() + " 分");
cell = row.createCell((short) 12);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if (teacher.getFlag()) {
cell.setCellValue("已申核");
} else {
cell.setCellValue("未申核");
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
wb.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
}
byte[] content = outputStream.toByteArray();
InputStream inputStream = new ByteArrayInputStream(content);
return inputStream;
}
如果我的数据库用的是SQLServer2005 能下载但是不能query.setFirstResult(start);query.setMaxResults(number);这个的分页语句,用的话就报错。可是,下载可以用的。
如果用MySQL可以分页也能用query.setFirstResult(start);query.setMaxResults(number);不用报错,但是下载不能用。已经一个星期了,我怎么都搞不出来,很郁闷,请大虾来帮帮我,谢谢您们了。
这个是下载成Excel的类,用着没有问题。
public InputStream getInputStream() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("编号");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("所在部门");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("姓名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("性别");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("出生日期");
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学历");
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("学位");
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("现职称");
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("取得现职称日期");
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("专业名称");
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("必修(已通过)");
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("选修(总分)");
cell = row.createCell((short) 12);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("申核状态");
List<Teacher> list = this.listTeacher();
for (int i = 0; i < list.size(); i++) {
Teacher teacher = list.get(i);
row = sheet.createRow(i + 1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(i + 1);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getDepartment());
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getName());
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getSex());
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell
.setCellValue(teacher.getBirthday().toString().substring(0,
10));
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getDegree());
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getEducation());
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getPost());
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell
.setCellValue(teacher.getPosttime().toString().substring(0,
10));
cell = row.createCell((short) 9);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getProfressional());
cell = row.createCell((short) 10);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getCompulsoryresult());
cell = row.createCell((short) 11);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(teacher.getEletiveresult() + " 分");
cell = row.createCell((short) 12);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
if (teacher.getFlag()) {
cell.setCellValue("已申核");
} else {
cell.setCellValue("未申核");
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
wb.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
}
byte[] content = outputStream.toByteArray();
InputStream inputStream = new ByteArrayInputStream(content);
return inputStream;
}
作者: shuaileitj 发布时间: 2011-03-12
这貌似和apache没关系
作者: ashchen 发布时间: 2011-03-15