I have a java project and placed sql file(backup) in this project.
how to Restore this file inside library to mysql with java(Restore of jar file)?
-
Maybe this can help you: stackoverflow.com/questions/8437240/…HectorLector– HectorLector2012-02-13 22:37:54 +00:00Commented Feb 13, 2012 at 22:37
2 Answers
Is this against a remote server? If you are not opposed to combining Java with the MySQL command line client then you can just do:
Runtime.getRuntime().exec("/usr/bin/mysql <your connection options> < your_sql_backup.sql");
If you want it all native Java then you'll end up needing to parse your sql backup and execute the queries through JDBC.
Comments
Run mysql -uUSERNAME -pPASWORD SCHEMA <yourfile.sql. You can use either Runtime.getRuntime().exec() or ProcessBuilder to execute external program.
The mysql command requires redirect to restore data. You can either create shell script/batch file (depending on your operating system) and run it from java or run command line like cmd /c mysql... or /bin/sh mysql directly from java application (again, depending on your OS)