Reputation: 21
I am trying to develop an Android app that will access the Database from AWS S3 server. I have tried doing it the normal way just by adding the the connection string i.e. the db link I got from aws S3 server bucket. 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. I dont know if that is the right approach. I'm new to android development and aws too.
Upvotes: 0
Views: 5221
Reputation: 10444
Sqlite is an embedded database that does not consume a lot of resources. 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. 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.
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.
Upvotes: 1