简体   繁体   English

如何将存储在AWS S3服务器中的sqlite数据库远程连接到我的android应用

[英]How do I connect a sqlite DB stored in AWS S3 server to my android app remotely

I am trying to develop an Android app that will access the Database from AWS S3 server. 我正在尝试开发一个Android应用程序,该应用程序将从AWS S3服务器访问数据库。 I have tried doing it the normal way just by adding the the connection string ie the db link I got from aws S3 server bucket. 我尝试通过添加连接字符串即从aws S3服务器存储桶中获得的数据库链接来以正常方式进行操作。 I have given permission also to that bucket. 我也允许那个水桶。 But when I run the app it say "could open Database". 但是,当我运行该应用程序时,它说“可以打开数据库”。 Is there a way I can do it easily? 有什么办法可以轻松做到吗? You can check my DB adapter code connection code below. 您可以在下面查看我的数据库适配器代码连接代码。

public class DataBaseHelperAWS extends SQLiteOpenHelper {

    private SQLiteDatabase myDataBase;
    Date d = new Date();
    private final Context myContext;
    private static String  DB_PATH = "https://s3.ap-North-2.amazonaws.com/xxxx/test.db"; 

 public DataBaseHelperAWS(Context context) {
        super(context,  "https://s3.ap-North-2.amazonaws.com/xxxx/test.db" , null, 1);
this.myContext = context;
    }


public void openDataBase() throws SQLException {
        //Open the database
        try {
            String myPath = DB_PATH ;

            myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
        } catch (SQLiteException e) {
     }
}

    public Cursor GetData(String query) throws SQLException {

        //Open the database
        Cursor resultSet = null;
        try {
            openDataBase();
            resultSet = myDataBase.rawQuery(query, null);
            resultSet.moveToFirst();
        } catch (SQLException e) {
    }
}

public void ExecuteQuery(String query) throws SQLException {

        //Open the database
        try {
            openDataBase();
            myDataBase = this.getWritableDatabase();
            myDataBase.execSQL(query);
        } catch (Exception e) {
}
}

  public synchronized void close() {
        try {
            if (myDataBase != null)
                myDataBase.close();

            super.close();
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }

    }
}

Please check the code that I have tried. 请检查我尝试过的代码。 I used my local db adapter/dbhelper class to access the remote aws server using the aws link. 我使用本地数据库适配器/ dbhelper类通过aws链接访问远程aws服务器。 I dont know if that is the right approach. 我不知道这是否是正确的方法。 I'm new to android development and aws too. 我是android开发和AWS的新手。

Sqlite is an embedded database that does not consume a lot of resources. Sqlite是一个嵌入式数据库,不占用大量资源。 The idea is to embed it inside of your app. 想法是将其嵌入到您的应用程序内部。 Android has sqlite embedded inside of it, so that you can write apps to connect to store data in it. Android内部嵌入了sqlite,因此您可以编写应用程序来连接以在其中存储数据。 The database lives on the device and cannot live on a server. 数据库位于设备上,而不能位于服务器上。

However, if your sqlite database in S3 does not change very often, you could download the file onto the device periodically and update the local copy of the database . 但是,如果S3中的sqlite数据库更改不是很频繁,则可以定期将文件下载到设备上并更新数据库的本地副本

If you need the databases to always be in sync, it may probably be better to use a database service such as DynamoDB , but you still may want to cache the results in a local sqlite table for the times that the user does not have internet access. 如果您需要数据库始终保持同步,则最好使用DynamoDB之类数据库服务 ,但在用户无法访问Internet的情况下 ,您仍可能希望将结果缓存在本地sqlite表中。

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

相关问题 如何将 aws S3 集成到我的 android 应用程序中? - How to integrate aws S3 to my android app? 如何在本地将本地数据库连接到我的Android应用程序? - How can I connect local db to my Android app locally? 如何将我的sqlite数据库连接到我的java swing GUI? - How do i connect my sqlite db to my java swing GUI? 带Android的SQLite,如何连接到在线数据库? - SQLite with android, how do you connect to online db? 有没有一种方法可以在不使用适用于Android的AWS开发工具包的情况下将多部分上传到Android应用程序上的S3存储桶中? - Is there a way to do multi-part uploads to my S3 bucket on an android app without using the AWS SDK for android? 如何将我的Android应用程序连接到远程MySQL数据库? - How do I connect my Android app to a remote MySQL database? 我应该为我的Android应用程序使用SQLite数据库还是只使用JSON? - Should I be using a SQLite db for my Android app or just JSON? 如何使用存储在 hdfs 中的 jceks 文件连接到 aws sqs queue 和 s3 - How to use jceks file stored in hdfs to connect to aws sqs queue and s3 如何在 android 应用程序中将登录数据与我的 SQLite 数据库进行比较? - How can I compare login data with my SQLite DB in android app? 如何使用Java远程连接到服务器中的MongoDB? - How to remotely connect to my MongoDB in my server with java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM