1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package exportmysql;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import javax.swing.JFileChooser;
/**
*
* @author DIAKITE
*/
public class Exportmysql {
public static void main(String[] args) {
JFileChooser filechoose = new JFileChooser();
filechoose.setCurrentDirectory(new File("."));
//String approve = new String("ENREGISTRER");
int resultatEnregistrer = filechoose.showDialog(filechoose,"ENREGISTRER");
if (resultatEnregistrer ==JFileChooser.APPROVE_OPTION)
{ String monFichier= new String(filechoose.getSelectedFile().toString());
if(monFichier.endsWith(".sql")|| monFichier.endsWith(".sql"))
{
;
}
else
{monFichier = monFichier+ ".sql";}
File test=new File(monFichier);
PrintStream ps;
try {
Process p = Runtime.getRuntime().exec(new String[]{
"c:\\Program Files\\MYSQL\\MYSQL Server 5.6\\bin\\mysqldump.exe", "-u", "root", "-pmotdepasse", "--opt", "world", "city"
});// BD=world table=city
ps=new PrintStream(test);
InputStream in = p.getInputStream();
int ch;
while ((ch = in.read()) != -1) {
ps.write(ch);}
} catch (IOException e) {
System.out.println(e.toString());
}
catch(Exception exc) {
exc.printStackTrace();
}
System.out.println("sauvegarde effectuée vers "+monFichier);
}
}
} |
Partager