[英]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.