问题
I have two method in SQLiteConnection class, which is
public void UserA(String user, String name, String email, byte[] blob){};
and
public void UserB(String user, String name, String email, byte[] blob){};
I want to combine the value that get in this two method, pass it the third method which use to store in sqlite database.
public void TwoUser(String user1, String name1, String email1, byte[] blob1, String user2, String name2, String email2, byte[] blob2){};
But I don't know how to access the value(String user, String name, String email, byte[] blob) that I get in UserA(), and use it in TwoUser().
What method can be use to get the value in UserA(), and use it in TwoUser().
Or is it possible I save the UserA in TwoUser database first, when I get the data from UserB then update the TwoUser database? Mean separate save the data under same column? Is it possible?
EDIT
My project is use for swap item, firstly all user need to upload their item so I saved item data in the database as show below.
Next userA will choose the item from UserB, so finally I want to store both item data in new database show I can so the result so swapping.
Here is the database that used to store the different user data.
That is the result I want, upper one show the UserA item detail, below is the Swap result from UserA and UserB.
public void insertItem(String user, String name, String condition, String email, String category,byte[] blob) {
ContentValues cv = new ContentValues();
cv.put(ItemDb.USER, user);
cv.put(ItemDb.NAME, name);
cv.put(ItemDb.CONDITION, condition);
cv.put(ItemDb.EMAIL, email);
cv.put(ItemDb.CATEGORY, category);
cv.put(ItemDb.IMAGE,blob);
db = sqlHp.getWritableDatabase();
db.insert(ItemDb.TABLE, null, cv);
db.close();
}
回答1:
It's a redudancy method you're using above, UserA and UserB have same parameter (and same function maybe). If I were you, I would make it like (one method only):
public void user(String user[], String name[], String email[], byte blob[]){
String user1=user[0], user2=user[1];
String name1=name[0], name2=name[1];
String email1=email[0], email2=email[1];
byte blob1=blob[0], blob2=blob[1];
//What to do next
}
来源:https://stackoverflow.com/questions/16907038/reading-values-from-one-database-and-write-it-to-another-database