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.
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'm trying to update a row in my database. Here is the code I am trying to use to update:
public void addFBComments(int id){
SQLiteDatabase db = this.getWritableDatabase();
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id;
db.execSQL(query);
}
When I run the command, it throws this error:
08-18 15:42:10.145: E/AndroidRuntime(10493): FATAL EXCEPTION: Thread-922
08-18 15:42:10.145: E/AndroidRuntime(10493): android.database.sqlite.SQLiteException: no such column: HELLO (code 1): , while compiling: UPDATE fb_feed SET fb_comments= HELLO WHERE _id=3
Here is the TABLE_FB_FEED:
private static final String TABLE_FB_FEED_CREATE = "create table " + TABLE_FB_FEED +
" ("
+ COL_FB_ID + " integer primary key autoincrement not null,"
+ COL_FB_MESSAGE + " text,"
+ COL_FB_CAPTION + " text,"
+ COL_FB_POSTER_ID + " text,"
+ COL_FB_POST_ID + " text,"
+ COL_FB_LIKES + " text,"
+ COL_FB_POSTER_NAME + " text,"
+ COL_FB_COMMENTS + " text," // this is the column i want to update
+ COL_FB_LIKES_NUM + " text,"
+ COL_FB_TIMESTAMP + " text,"
+ COL_FB_PROFILE_PICTURE_URI + " text,"
+ COL_FB_PICTURE_URI + " text,"
+ COL_FB_NAME + " text,"
+ COL_FB_PREVIOUS_PAGE_URI + " text,"
+ COL_FB_NEXT_PAGE_URI + " text,"
+ COL_FB_POST_TYPE + " text,"
+ COL_FB_LINK_NAME + " text,"
+ COL_FB_COMMENTS_NUM + " text,"
+ COL_FB_STORY + " text,"
+ COL_FB_DESCRIPTION + " text,"
+ COL_FB_COMMENTS_BEFORE + " text,"
+ COL_FB_COMMENTS_AFTER + " text,"
+ COL_FB_LIKES_PROFILE_PIC + " text,"
+ COL_FB_COMMENTS_PROFILE_PIC + " text);";
Why is it throwing the query? I thought I was doing everything correctly.
in your code you need to add single quotes:
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
+"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id
or
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
+"='HELLO' WHERE " + COL_FB_ID+"="+id
this is another example
"UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=myidValue");
In SQL, string values must be quoted:
String query = "..." + COL_FB_COMMENTS+"= 'HELLO' WHERE ...";
Anyway, formatting problems such as this (which get worse when the string itself contains quotes) can be avoided by using parameters:
String query = "... SET " + COL_FB_COMMENTS+"= ? WHERE " + COL_FB_ID+"="+id;
db.execSQL(query, new Object[] { "HELLO" });
You need to escape your String literal,
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
+"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id
Could be
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS
+"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id
Or, you could use a bind parameter.
something like
String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id;
would work
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";
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].
I would like to insert a carriage return into a cell of a xls file.
So I have written this code
address = rs.getString(16) + " " + rs.getString(17) + "
"
+ rs.getString(18) + " " + rs.getString(19) + " (" +
rs.getString(20) + ")";
"writer.write("<ss:Cell><ss:Data ss:Type=\"String\">" + address + "</ss:Data></ss:Cell>");`
but in the Excel File the result is that the carriage return is replaced with a "square symbol". In which mode can I resolve this issue?
Thanks,
Stefano
In excel, to enter a new line in a cell, you need to insert ASCII characters 13 + 10 (constant CrLf on this page : http://msdn.microsoft.com/en-us/library/f63200h0%28v=vs.80%29.aspx).
Have you tried:
String crLf = Character.toString((char)13) + Character.toString((char)10);
address = rs.getString(16) + " " + rs.getString(17) + crLf
+ rs.getString(18) + " " + rs.getString(19) + " (" +
rs.getString(20) + ")";