使用ApachePOI将mysql数据从Java导出到excel
我从这里复制了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");
但没有任何错误,文件也不完整。xls仍为空白。 有人知道问题出在哪里吗
# 1 楼答案
您可能必须显式关闭outputStream,而不是这样做:
你应该尝试这样做: