In this tutorial I show you to get mysql backup using java application. In hare include a video there are step by step how make it. And all source code include this post.
Step 1 - choose backup path
private void btnbrowsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbrowsActionPerformed
JFileChooser jfc= new JFileChooser();
jfc.showOpenDialog(this);
String date=new SimpleDateFormat("yyy-MM-dd").format(new Date());
try {
File f= jfc.getSelectedFile();
path=f.getAbsolutePath();
path=path.replace('\\', '/');
path = path + "_" + date + ".sql";
txtpath.setText(path);
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
JFileChooser jfc= new JFileChooser();
jfc.showOpenDialog(this);
String date=new SimpleDateFormat("yyy-MM-dd").format(new Date());
try {
File f= jfc.getSelectedFile();
path=f.getAbsolutePath();
path=path.replace('\\', '/');
path = path + "_" + date + ".sql";
txtpath.setText(path);
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
Step 2 - get backup
private void btnbackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbackupActionPerformed
int x=txtpath.getText().length();
if(x>0)
{
try {
Runtime run= Runtime.getRuntime();
pr=run.exec("C://wamp64//bin//mysql//mysql5.7.21//bin//mysqldump.exe -uroot --add-drop-database -B computer_shop -r"+ path);
int processComplete= pr.waitFor();
if(processComplete==0)
{
JOptionPane.showMessageDialog(rootPane, "Backup Success");
}
else
{
JOptionPane.showMessageDialog(rootPane, "Fail");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
else
{
JOptionPane.showMessageDialog(rootPane, "Select Path");
}
}
int x=txtpath.getText().length();
if(x>0)
{
try {
Runtime run= Runtime.getRuntime();
pr=run.exec("C://wamp64//bin//mysql//mysql5.7.21//bin//mysqldump.exe -uroot --add-drop-database -B computer_shop -r"+ path);
int processComplete= pr.waitFor();
if(processComplete==0)
{
JOptionPane.showMessageDialog(rootPane, "Backup Success");
}
else
{
JOptionPane.showMessageDialog(rootPane, "Fail");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
else
{
JOptionPane.showMessageDialog(rootPane, "Select Path");
}
}
hello sir i am make a bank management software in neatbeans and database in xammp server. i done coding but its not work please help before 20/12/2018 because my project submit on 20/12/2018
ReplyDeletecoding:-
File choose
JFileChooser jfc= new JFileChooser();
jfc.showOpenDialog(this);
String date=new SimpleDateFormat("yyy-MM-dd").format(new Date());
try {
File f= jfc.getSelectedFile();
path=f.getAbsolutePath();
path=path.replace('\\', '/');
path = path + "_" + date + ".sql";
jTextField1.setText(path);
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
Backupcode:-
int x=jTextField1.getText().length();
if(x>0)
{
try {
Runtime run= Runtime.getRuntime();
pr=run.exec("C://xampp//mysql//bin//mysqldump.exe -uroot --add-drop-database -B banking -r"+ path);
int processComplete= pr.waitFor();
if(processComplete==0)
{
JOptionPane.showMessageDialog(rootPane, "Backup Success");
}
else
{
JOptionPane.showMessageDialog(rootPane, "Fail");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
else
{
JOptionPane.showMessageDialog(rootPane, "Select Path");
}
This is not workinh it always generate the messages that " Fail " kindly help me as soon as possible
ReplyDelete