I already export MySQL database.Now i want to know database name present in dump file through java code.I require this because, if database present in dump file is not present in server then first i want to create database and then import it.I do not know is this possible or not? suggest any answer..
-
If your dump has a database creation statement, then why do you need to find the database name?Akira– Akira2013-11-16 10:34:42 +00:00Commented Nov 16, 2013 at 10:34
-
1what kind of command did you use to dump MySQL database, if you are using mysqldump, then the dump file is possibly a txt file, you can read it using Java. As far as I know, mysqldump with default parameters would dump the database name into the file.vivisidea– vivisidea2013-11-16 10:34:46 +00:00Commented Nov 16, 2013 at 10:34
-
That is also my point. Simply searching for "CREATE DATABASE X" would solve the problem. But if you apply the whole dump, why bother finding something you already know?Akira– Akira2013-11-16 10:46:49 +00:00Commented Nov 16, 2013 at 10:46
Add a comment
|
1 Answer
Put your data base connecting code in try catch. If you get an Unknown database exception then write the code for creation of the data base in catch block
for example:
try{
System.out.println("Connecting to database");
con=DriverManager.getConnection("jdbc:mysql://localhost/iie1","root","");
System.out.println("Database connected ");
}catch(Exception e)
{
System.out.println("Creating data base");
// Code for creating data base
}