How import and export .sql file by query. notice Using in jdbc
Asked
Active
Viewed 4,045 times
0
-
Are you asking about creating and loading an SQL dump file? If so, then the simple way is to use the database's sql dump / restore utilities, not JDBC. Just call it using the `Process` class. – Stephen C Nov 07 '15 at 07:06
-
I want to store my data in my drive D or E by java app . I'm afraid of losing my data – Amr Emaish Nov 07 '15 at 07:13
-
And I have not more experience in Sql to do that – Amr Emaish Nov 07 '15 at 07:14
1 Answers
2
The importing part of your question has already been asked here "How to execute .sql script file using JDBC"
To do exporting you need to create a SQL queries to get data from every table in your database. Then write that data out to a file.
Your task of exporting data would be more simple using sql dump utilities, or MYSQL workbench.
Do export a single database via command line you can do this:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
More command line options for SQL can be found here: "MySQL: How to export and import an .sql file from command line?"
-
-
-
Work only in CMD ?? $ mysqldump -u [uname] -p[pass] db_name > db_backup.sql – Amr Emaish Nov 07 '15 at 07:24
-
@AmrEmaish - That is correct ... though you can run that using `java.lang.Process` via a BAT or shell script. – Stephen C Nov 07 '15 at 10:41
-