我正在尝试从MySQL数据库(保留)导出单个表(位置),但我不能通过使用java来实现。请帮帮我。
preparedStatement = connection.prepareStatement("mysqldump –uroot –proot keep location> db_test.sql");
preparedStatement.execute();
connection.close();
答案 0 :(得分:1)
对于单个表,这里是代码。我们可以将此表保存到文件中。
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/abc";
String username = "root";
String password = "root";
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
String filename = "d:/outfile.sql";
String tablename = "abc";
stmt.executeQuery("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);