Ali yasar Erdogan
Ali yasar Erdogan

Reputation: 97

I can't export database using java. Can anyone help me?

I am trying to export a single table (location) from MySQL database (keep) but i can't do it by using java. Please help me.

preparedStatement = connection.prepareStatement("mysqldump –uroot –proot keep location> db_test.sql");
        preparedStatement.execute();
        connection.close();

Upvotes: 0

Views: 57

Answers (1)

SatyaTNV
SatyaTNV

Reputation: 4135

For a single table here is the code. We can save this table to a file.

    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);

Upvotes: 1

Related Questions