3

MysqlToXls从这里复制了课程:http: //mikescode.wordpress.com/2008/02/16/exporting-a-mysql-table-to-excel-xls-in-java/

我以这种方式编辑了创建不需要任何参数的构造函数的类:

public MysqlToXls()
throws ClassNotFoundException, SQLException {

    // Create MySQL database connection
    Class.forName("com.mysql.jdbc.Driver");

    String url = "jdbc:mysql://localhost/Spinning?user=root&useUnicode=true&characterEncoding=utf8";
    connection = DriverManager.getConnection(url);
}

虽然没有任何指南,但我尝试自己做,但我做不到。

  MysqlToXls m=new MysqlToXls();
  m.generateXls("utente", "utenti.xls");

但是没有错误,文件 utenti.xls 保持空白。有人知道问题出在哪里吗?

4

2 回答 2

1

唯一的问题是文件的路径。我试图将文件保存在项目的一个文件夹中(使用相对路径),而如果我给出绝对路径(桌面上的 fe),它可以完美地工作!

于 2013-02-10T11:37:41.190 回答
1

您可能必须显式关闭 outputStream,因此建议这样做:

xlsWorkbook.write(new FileOutputStream(filename));

你应该尝试做这样的事情:

FileOutputStream fos = new FileOutputStream(filename);
xlsWorkbook.write(fos);
fos.close();
于 2013-02-09T13:12:00.340 回答