Click here to Skip to main content
14,304,263 members
Rate this:
Please Sign up or sign in to vote.
Hello,
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());
        }

    }
}


Thanks for the help.

What I have tried:

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.
Posted
Updated 5-Oct-16 3:25am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I don't think you can use SQLiteDatabase.openDatabase method for a remote sql lite call. It appears that sql lite has to be on the device or sd card.

Can Android SQLiteDatabase.openDatabase() be used to open a remote sqlite database? - Stack Overflow[^]

Now if you are trying to centralize your database so that multiple hardware devices call the same database you should look at exposing your database via web service and then have your many different device platforms make calls to that web service rather than trying to host it on s3. Which by the way, if you are doing it the way it appears, you've made your s3 sql lite DB public without requiring a presigned url.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100