简体   繁体   English

在 android studio 中将两个或多个数据库的表相互连接

[英]Connecting tables of two or more databases with each other in android studio

I just wanted to know if there is any way to connect two tables of two different databases under one project.我就想知道有没有什么办法可以在一个项目下连接两个不同数据库的两个表。 I have the databases as follow我有如下数据库

First database第一个数据库

private String CREATE_USER_TABLE = "CREATE TABLE  "+ TABLE_USER + "(" +
        COLUMN_USER_ID +" INTEGER PRIMARY KEY AUTOINCREMENT , " + COLUMN_USER_MOBILE + " TEXT," + 
        COLUMN_USER_EMAIL + " TEXT, "
        + COLUMN_USER_MOTHERNAME + " TEXT, " + COLUMN_USER_FATHERNAME + " TEXT, " +
        COLUMN_USER_PASSWORD + " TEXT, " + COLUMN_USER_CONFIRM_PASSWORD + " TEXT " + ")";

Second database第二个数据库

        private String CREATE_BABY_TABLE = "CREATE TABLE "+ TABLE_BABY + "(" +
        COLUMN_BABY_ID + " INTEGER  PRIMARY KEY AUTOINCREMENT , " + COLUMN_BABY_NAME + " TEXT, "
        + COLUMN_BABY_DATE + " TEXT, " + COLUMN_BABY_GENDER + " TEXT, " + COLUMN_BABY_AGE + 
          " TEXT " + ")";

Yes, application can has connect to different databases.是的,应用程序可以连接到不同的数据库。 (By clear sqlite or any db library, like Room) But your question contains two tables but not two databases. (通过清除 sqlite 或任何数据库库,如 Room)但是你的问题包含两个表而不是两个数据库。 You must just put them to one database.你必须把它们放到一个数据库中。

The standard solution to this is to query each of the databases separately and then merge or join the results in your application logic.对此的标准解决方案是分别查询每个数据库,然后将结果合并或加入您的应用程序逻辑中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM