使用AutoStatisticUser时出问题

cldonkey 2014-03-29 01:05:19
我在写一个关于在java服务器下,操作数据库将ResultSet结果集中的数据导入到Excel表中程序。完全借用了别人的代码,我是在database.java中创建了此函数代码如下public static boolean DB2Excel(ResultSet rs, String fileName) {
boolean flag = false;
WritableWorkbook workBook = null;
WritableSheet sheet = null;
Label label = null;

try {
// 创建Excel表
String path = AutoStatisticUser.class.getResource("").getPath()
+ fileName;
workBook = Workbook.createWorkbook(new File(path));
// 创建Excel表中的sheet
sheet = workBook.createSheet("First Sheet", 0);
// 向Excel中添加数据
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String columnName = null;
int row = 0;
// 添加标题
for (int i = 0; i < columnCount; i++) {
columnName = rsmd.getColumnName(i + 1);
label = new Label(i, row, columnName);
System.out.println("标题:" + i + "---" + row + "---"
+ columnName);
sheet.addCell(label);
}
row++;
System.out.println("写入标题成功");
while (rs.next()) {
for (int i = 0; i < columnCount; i++) {
label = new Label(i, row, rs.getString(i + 1));
System.out.println("标题:" + i + "---" + row + "---"
+ rs.getString(i + 1));
sheet.addCell(label);
}
row++;
}
System.out.println("写入内容成功");
// 关闭文件
workBook.write();
System.out.println("数据成功写入Excel");
flag = true;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
workBook.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return flag;
}
但是在创建excel的那段代码会出错如图。不知哪位大神知道,请给小弟说下
...全文
166 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cldonkey 2014-04-02
  • 打赏
  • 举报
回复
接着来,自己完善掉。但愿给后来人有点帮助。File fiel1=new FIle("."); path=fileName+file1;
cldonkey 2014-04-01
  • 打赏
  • 举报
回复
好吧,对于这样的问题。我还是自己努力解决了。就当是给自己做个笔记,为后来人做个参考。下面都是自己个人见解: 首先,这段代码调用这个类以及后面的函数,目的就是为了创建文件保存的路径。我怎么修改的呢。 String path = AutoStatisticUser.class.getResource("").getPath() + fileName; 修改成了:(下个回复写,竟然把代码拷贝错了明天写)
  • 打赏
  • 举报
回复
你程序里没有这个类 当然会报这个错啊
cldonkey 2014-03-31
  • 打赏
  • 举报
回复
人呢···················
cldonkey 2014-03-29
  • 打赏
  • 举报
回复
自己先给自己顶起,来人 啊。大神何处去了

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧