I have an application written in JSP running in Apache Tomcat Server and back end is MySQL and m having problem in my code tried many things
like creating a .bat file but dint got a code to run .bat file from jsp page.
Also the following code i tried but not working

String user = "root";
String password = "root";
String database = "egateway";
String filepath = "e:\\data.sql";

String stmt1 = "mysqldump" + database + "-u" + user + "-p" + password + "- default-character-set = gb2312 - result-file =" + filepath;

try {
Runtime r = Runtime.getRuntime ();
Process p = r.exec(stmt1);
out.println ( "data has been exported to the file" + filepath + "successfully nidhish");

i know how to do it command prompt but how in jsp page dont know please help me

catch(IOException e)
e.printStackTrace ();

7 Years
Discussion Span
Last Post by itz.aayushi

good, that's such terrible code it should never work.
Even if it were syntactically correct (I didn't even bother to check) it's conceptionally so utterly wrong it should just give up and die.


When exporting data out of a MySQL table/database, you should use the following SQL code:

INTO OUTFILE 'filename/location'
FROM table_name;

My assumption would be to run a statement query execute. In terms of the whole DB at once, im sorry, but im not entirely sure.


f you still looking for quick and dirty solution then have look at this http://forums.sun.com/thread.jspa?me...86505#10286505, but if you want to learn something better try Java Butcher (MySQL Backup Engine)

i tried both of your option but still not successfull

and you mentioned java butcher its an jar file can u explain me how can i use it to do the same

pls help me i m still unsuccessful

and i tried the code


try {
            Runtime runtime = Runtime.getRuntime();
            File backupFile = new File("backup/backupScript.sql");
            FileWriter fw = new FileWriter(backupFile);
            Process child = runtime.exec("mysqldump --user=root --password=pass --lock-all-tables --opt db_eonf");
            InputStreamReader irs = new InputStreamReader(child.getInputStream());
            BufferedReader br = new BufferedReader(irs);
            String line;
            while( (line=br.readLine()) != null ) {
                fw.write(line + "\n");
        } catch (IOException ex) {

but dis is just creating a .sql file and no data is added to it...????

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.