我正在尝试从mysql到csv文件执行2输出数据。 我的代码如下:
public void exportData(Connection conn,String filename) {
Statement stmt;
String query;
try {
stmt = conn.createStatement();
//For comma separated file
query = "SELECT * into OUTFILE '/tmp/input.csv' FIELDS TERMINATED BY ',' FROM router ";
stmt.executeQuery(query);
} catch(Exception e) {
e.printStackTrace();
stmt = null;
}
}
};
我在调用stmt.executequery的行中收到以下错误。
java.sql.SQLException: Access denied for user 'nxy'@'%' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2512)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1476)
at DBase.exportData(automateExport.java:50)
at automateExport.main(automateExport.java:18)
我能够正确连接数据库甚至执行基本查询,但无法将数据导出到.csv文件。 请帮忙。
谢谢