从一个数据库中读取值,并将其写入到另一个数据库 [英] Reading values from one database and write it to another database

查看:170
本文介绍了从一个数据库中读取值,并将其写入到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SQLiteConnection 类,这是

二步法

 公共无效用户A(用户字符串,字符串名称,字符串email,字节[] BLOB){};

 公共无效用户B(字符串用户名字符串,字符串电子邮件,字节[] BLOB){};

我想在这两年方法获得的价值结合起来,通过它而使用SQLite数据库来存储第三种方法。

 公共无效TwoUser(user1的字符串,字符串名称1,字符串EMAIL1,字节[] blob1,用户2字符串,字符串名称2,串EMAIL2,字节[] blob2){};

但我不知道如何访问值(字符串用户名字符串,字符串电子邮件,字节[] BLOB),我进去的用户A(),而在 TwoUser()

有什么方法可以使用​​来获取值的用户A(),并在使用它的 TwoUser()

或者是有可能我保存用户a在TwoUser数据库第一次,当我得到UserB的数据,然后更新TwoUser数据库?意思是单独保存在同一列中的数据?可能吗?

修改

我的项目是使用了交换项目,首先所有的用户需要,所以我在数据库中,如下所示保存的项目数据上传他们的项目。

下一页用户A会选择从用户B的项目,所以最后我想要存储在新的数据库显示两个项目的数据,我可以这样的结果让交换。

下面是用于存储不同的用户数据的数据库。

这就是我想要的,上层显示用户A项细节的结果,下面是a和UserB的交换的结果。

 公共无效insertItem(字符串用户名字符串,字符串条件,字符串电子邮件,字符串类型,字节[] BLOB){
        ContentValues​​ CV =新ContentValues​​();
        cv.put(ItemDb.USER,用户);
        cv.put(ItemDb.NAME,名);
        cv.put(ItemDb.CONDITION,条件);
        cv.put(ItemDb.EMAIL,电子邮件);
        cv.put(ItemDb.CATEGORY,类别);
        cv.put(ItemDb.IMAGE,BLOB);
        DB = sqlHp.getWritableDatabase();
        db.insert(ItemDb.TABLE,空,CV);
        db.close();
    }


解决方案

这就是你利用一个redudancy方法,a和UserB具有相同的参数(也许是相同的功能)。
如果我是你,我会做它像(只有一个方法):

 公共无效用户(用户字符串[],字符串名称[],字符串email [],字节BLOB []){  字符串的user1用户= [0],user2的用户= [1];
  字符串名称1 =名称[0],名称2 =名称[1];
  字符串EMAIL1 =电子邮件[0],EMAIL2 =电子邮件[1];
  字节blob1 =斑点[0],blob2 =斑点[1];  //接下来做什么}

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();
    }

解决方案

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

}

这篇关于从一个数据库中读取值,并将其写入到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆