What are the possible reasons why i can't backup my DB using MYSQLDUMP?
In my localhost, i can backup the db but when I use the db in my hosting, there seems to be a problem. Is it possible that my hosting can't backup db? Btw, im using cloudbees in my database. I'm 100% sure that I change all the username, password and the name of the db when using my hosting MySQL. Actually it creates the .sql file but it is empty.
String executeCmd = "C:/xampp/mysql/bin/mysqldump -u " + username
+ " -p" + password + " somedbname" + " -r "
+ "C:/tech-report-db/backup"
+ c.getTimeInMillis() + c.getWeekYear() + ".sql";
try {
Process runtimeProcess;
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Backup created successfully");
} else {
System.out.println("Could not create the backup");
}
it returns the error "Could not create the backup"
I fixed the problem. Sorry for incomplete question. I'm using a remote mysql so i need to include the hostip and the port
before:
String executeCmd = "C:/xampp/mysql/bin/mysqldump -u " + username
+ " -p" + password + " somedbname" + " -r "
+ "C:/tech-report-db/backup"
+ c.getTimeInMillis() + c.getWeekYear() + ".sql";
now:
String executeCmd = "C:/xampp/mysql/bin/mysqldump -P "+port+ " -h "+hostIP+ " -u " + username
+ " -p" + password + " somedbname" + " -r "
+ "C:/tech-report-db/backup"
+ c.getTimeInMillis() + c.getWeekYear() + ".sql";
Related
I am trying to call a java service from python. I am appending current timestamp to the file name to create a dynamic file name and passing it as a parameter in the java command. When I don't append the timestamp and pass the parameter as is, the code works but when I append the timestamp, I get Uncaught exception spotted in thread main: java.lang.AbstractMethodError error.
The code that doesn't works:
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
timestr = time.strftime("%Y%m%d - %H%M%S")
log_file_name = "..\logs\DHLogFile" + timestr + ".log"
print(log_file_name)
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The code that works,
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
log_file_name = "..\logs\DHLogFile.log"
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The full error is:
E 28/12/17-11:37:36.358 [-5] Uncaught exception spotted in thread main: java.lang.AbstractMethodError
E 28/12/17-11:37:36.358 [-5] java.lang.AbstractMethodError :
lib.main.a$a.a([Ljava/lang/String;I)I
java.lang.AbstractMethodError: lib.main.a$a.a([Ljava/lang/String;I)I
at lib.main.a.processArgs(SourceFile:646)
at lib.main.a.setupEnv(SourceFile:1078)
at lib.main.Server.main(SourceFile:157)
Could you please help me understand what is giving me AbstractMethodError Exception as I really want to have timestamp in the filename.
I have developed a Java application and it's in last stage.
The problem is that I cannot execute the mysqldump with Runtime.getRuntime().exec().
try {
String[] command = new String[] {
"cmd.exe",
"/c",
"mysqldump --host=" + host + " --user=" + dbuser + " --password=" + dbpass + " " + dbname + " > " + filename
};
Process runtimeProcess = Runtime.getRuntime().exec(command);
int ProcessComplete = runtimeProcess.waitFor();
if (ProcessComplete == 0) {
JOptionPane.showMessageDialog(null, "Database backup has been done successfully");
}
else {
JOptionPane.showMessageDialog(null, "Database backup was unsuccessfull");
JOptionPane.showMessageDialog(null, command);
}
}
catch (IOException | InterruptedException exc) {
Logger.getLogger(Backup.class.getName()).log(Level.SEVERE, null, exc);
}
Can anyone help me with this?
I tried your code in Windows and it works fine for me.
Open cmd, type mysqldump and hit enter.
If it is executed successfully, that means your code should work properly if your database configuration is correct.
If you get 'mysqldump' is not recognized as an internal or external command then either you have to set the MySQL path in your environment variable, or specify the full path for mysqldump in your Java code like this:
String[] command = new String[] {
"cmd.exe",
"/c",
"c://mysql/bin/mysqldump --host=" + host + " --user=" + dbuser + " --password=" + dbpass + " " + dbname + " > " + filename
};
I can get a terminal window or command prompt to open on either Mac OS or Windows. I want to send a string to that terminal or cmd window using my java.
String in = " -i " + "\"" + tfIntdta.getText() + "\"";
String rst = " - r " + "\"" + tfRstplt.getText() + "\"";
String out = " -o " + "\"" + tfOutdta.getText() + "\"";
String strip = " -s" + "\"" + tfStpdta.getText() + "\"";
String guistring = "-n gui";
String wd = "\"" + System.getProperty("user.dir");
String osver = System.getProperty("os.name");
String app = "";
if (osver.contains("Mac")){
app = wd + "/relap5.x\"";
} else if (osver.contains("Windows")){
app = "\\relap5.exe";
} else if (osver.contains("linux")) {
app = "/relap5.x";
}
String run = app + in + rst + out;
So the string would look something like this.
"/Users/brianallison/Documents/Java/RELAP5 GUI/issrs/relap5.x" -i "" - r "" -o ""
I want the line above to appear on the terminal or cmd window and execute.
Put your command and parameters in an array:
String[] command = {
"/Users/brianallison/Documents/Java/RELAP5 GUI/issrs/relap5.x",
"-i", "Choose your input file",
"-r", "",
"-o", ""
};
Then execute using Runtime#exec(String[] cmdarray):
Runtime.getRuntime().exec(command);
This answer has been put together after reading your other two questions from today, here and here.
I used mysqldump command to export/dump .sql file with rows like:
String cmd1 = mysqldump + " -h" + host + " -u" + username + " -p" + password + " " + "--compact --no-create-info " + "--where=ID=" + "'5b4ed36d-6152-4bfd-ad06-666f781e8bdc'" + " " + database + " " + "EMPLOYEE" + " " + "--result-file=" + "C:\\employee.sql";
This is the result of above command in a employee.sql file:
INSERT INTO `employee` VALUES ('Anette','Busch','2014-08-12','admin',' ','FALSE');
Now, I want to import the values from empolyee.sql file using command:
String cmd = mysql + " --user=" + username + " --password=" + password + " -e" + " source " + restoreFile;
The problem is I can't execute import command. I'm using the same import command for whole database, that works fine, but not in this case.
Thanks a lot for your guidance.
Lets assume, that we have some 2 tables in SQLite: TBL_PRODUCT and TBL_PRODUCT_ALIASES. Now, I want to query some data from joined two tables:
String sql = "SELECT " + TBL_PRODUCT + "." + C_PROD_PKEY_ID + ", " + TBL_PRODUCT_ALIASES + "." + C_PROD_ALIASES_PKEY_ID +
" FROM " + TBL_PRODUCT + " LEFT JOIN " + TBL_PRODUCT_ALIASES + " ON " + TBL_PRODUCT + "." + C_PROD_PKEY_ID + " = " + TBL_PRODUCT_ALIASES + "." + C_PROD_ALIASES_PKEY_ID +
" WHERE " + C_PROD_SERVER_ID + " = ? LIMIT 1";
Cursor cursor = SQLiteDataHelper.getInstance().rawQuery(sql, new String[] {"" + js_CartProduct.getLong("prod_id")});
Thats works great without any problem. And then I want to acquire some data from the returned cursor:
if (cursor.getCount() > 0) {
cursor.moveToFirst();
Long prodId = cursor.getLong(cursor.getColumnIndexOrThrow(TBL_PRODUCT + "." + C_PROD_PKEY_ID));
//... Some other code
}
Now, here is the problem: C_PROD_PKEY_ID and C_PROD_ALIASES_PKEY_ID are in the real world the same Strings: "_id". And as the result getLong() returns long not from the needed column of cursor.
How should I correctly address to the needed column? Are there other methods besides using AS in sql query OR/AND using definite numbers in cursor.getLong(0) instead of cursor.getLong(cursor.getColumnIndexOrThrow(TBL_PRODUCT + "." + C_PROD_PKEY_ID))?
Update:
cursor.getColumnNames() returns this: [_id, _id].