-1

I want to execute my program at 13:00 every day for example

this is my method that I want run in this time>

I hope the experts will write the solution

And, if possible, converted to Windows Service

In order to make the server take a backup at 13:00 every day:

public static void backup() throws IOException{

        try{
        String date = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
        String path="G:/DataBaseBackup/doctor_" + date + ".sql";
         String user="root";
         String password="12345";
         String db="doctor";


         Process runtimeProcess;
         String exeutedrun="\"C:/Program Files/MySQL/MySQL Server 5.7/bin/mysqldump.exe\" -u " + user + " -p" + password + " --routines --events   --add-drop-database -B " + db + " -r " + path;
         runtimeProcess=Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", exeutedrun });
         int processComplete = runtimeProcess.waitFor();
        System.out.println(path);
         if (processComplete == 0) {
             System.out.println("Data Base is Backup !!");

                error.write("Data Base is Backup in path : "+path);

         } else {
             System.out.println("Data Base is not Backup !!");

                error.write("Data Base is not Backup  : ");
         }



        }catch(Exception e){

            error.Exption(e);
            System.exit(1);

        }


    }
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
Younis
  • 35
  • 1
  • 6
  • If your question is "How do I set up a Windows Service", then it is off-topic for Stack Overflow as it is not a programming question. It may be on-topic on our sister site [Super User](https://superuser.com/). – Joe C Jul 08 '17 at 16:31

1 Answers1

3

Instead of writing into the code, export the code as runnable jar. Write a simple shell script for executing the jar save it as .cmd file. Then schedule the .cmd file into task scheduler for 13:00 everday.

Mandeep Singh
  • 91
  • 1
  • 1
  • 8