Programación General > Java

 Realizar Mysqldump Desde Java

(1/1)

rodry:
hola! tengo el siguiente código que compila y se ejecuta sin problemas, el problema es que una vez ejecutado no encuentro 'prueba.sql' es decir, es como si no hiciera nada.
 
--- Código: Text ---  public class ExportTest{   public ExportTest(){        try {      Runtime.getRuntime().exec("mysqldump -u root almacen > prueba.sql");                                        }catch(Exception e){      e.printStackTrace();    }  }    public static void main(String args[]){    new ExportTest();                  }} 
Gracias por anticipado. un saludo!

rodry:
Encontre una solución, aunque no me llega a convencer del todo, la pongo por si le pudiera valer a alguien:

--- Código: Text --- public class ExportTest{   public ExportTest(){        try {      Runtime.getRuntime().exec("cmd /C start c:/copia");                 }catch(Exception e){      e.printStackTrace();    }  }    public static void main(String args[]){    new ExportTest();                  }}  
siendo copia un archivo .bat con lo siguiente:

--- Código: Text --- mysqldump -u root almacen > c:\copia2sql  
Si alguien sabe de alguna solución que sirve tanto para linux como para windows sin necesidad de cambiar nada, y si es posible sin necesidad de utilizar un archivo externo se lo agradecería. Un saludo!

silverfox:
Hola...


A ver si te sirve lo siguiente...

http://forum.java.sun.com/thread.jspa?thre...ssageID=3411880


Suerte.



Silverfox

r589:
String dir="c:/Backup.sql";
     try{
       Runtime r = Runtime.getRuntime();
       Process p = r.exec("c:/mysql/bin/mysqldump.exe --add-drop-table Bd");
       InputStream is = p.getInputStream();
       BufferedReader br = new BufferedReader (new InputStreamReader (is));
       String aux = br.readLine();
       try{
           FileWriter fileout = new FileWriter(dir);
           BufferedWriter bw = new BufferedWriter(fileout);
           PrintWriter salida = new PrintWriter (bw);
           while (aux!=null){
              salida.println(aux);            
              aux = br.readLine();}
           salida.close();  
       }catch (Exception ww){
       System.out.println("Error");}
     }catch (Exception we){
     we.printStackTrace();}   

Espero te sirva, saludos

Navegación

[0] Índice de Mensajes

Ir a la versión completa