I am making an application on Android that will record stats from a sports game, I want to store the information obtained from the app to a MySql database. Can someone point me in the right direction please

3 Answers

0
Ahmed El-Nakib On

you just need to use any of network libraries like ( Volley , Retrofit , OkHttp ... etc ) if you use Volley Library you just need to install XAMPP and use phpMyAdmin to create your Database then learn mysql PHP using request methods like GET , POST then in Volley library in android just call ( Hashmap ) method to send data from android to mysql ... this picture will understand you what i meaning Volley android Sequence

0
Ehtisham Ali Shah On

On the app side you need network libraries that will send a request to the server to save/fetch the data from the server. These can be Retrofit/Volley/OkHttp etc. These network libraries will use an API (URL) to send or retrieve the data from the server.

On the back end side, you will need a web service to connect the SQL database and the app. The web service will provide an API (URL) that will be used by the App to send/retrieve the data. The web service can be made using PHP.

Of course you will need a server to host the web service files or locally you can try WAMP/XAMP etc. software to host and test the APIs but the mobile device and WAMP/XAMP server (i.e. computer/laptop) should be on the same network.

0
BradleighJL On

You will need to first initiate your sqlite database in its own class and then call it within your activity you want to store the results in e.g.

database class:

public class MyDB extends SQLiteOpenHelper {
//creates desired fields for app in db
public static final String DB_NAME = "mySQLiteDatabase";
public static final String TABLE_NAME = "results";
public static final String COLUMN_ID = "id";
//place your fields here e.g. result 1 

 public static final int DB_VERSION = 1;//version of database

public MyDB(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    String sql = "CREATE TABLE " + TABLE_NAME + " (" +
            COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // add the fields 
created here 
    sqLiteDatabase.execSQL(sql);

}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
    String sql = "DROP TABLE IF EXISTS " + TABLE_NAME;
    sqLiteDatabase.execSQL(sql);
    onCreate(sqLiteDatabase);

}  public boolean addResult(String result1, //etc 
   SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();

    ContentValues contentValues = new ContentValues();
    contentValues.put(//your column name, //your field );
    //other fields here e.g. result2 etc
       return sqLiteDatabase.insert(TABLE_NAME, null, contentValues) != -1;

}

after initialising something along the lines of this you can then use the addResult method in your main class