I am Using Java With MySQL (JDBC), and I want to import a dump file to database. what would be the correct way to do this?
I have tried the following code:
// function "connectToDB" connects to the Database, and not the server.
// variable sourcePath refers to the dumpfile.
Connection con = connectToDB(USERNAME, PASSWORD);
String q = "source " + sourcePath;
System.out.println("Q is: " + q);
try {
Statement statement = con.createStatement();
statement.executeUpdate(q);
} catch (Exception ex) {
ex.printStackTrace();
}
closeConnection(con);
but i get a MySQLSyntaxErrorException :
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘source C:…\Desktop\dumpfile.sql’ at line 1
Thank everyone for their help, reading Their Ideas, I finally imported the dumpfile.sql
So if anyone has the same problem, A sample code that worked for me is this:
EDIT: Adding the connectToDB function: