In this weeks I had to create a DB, accessible from anywhere, to be integrated in an application and web app for a work project.

This is a summary of the main steps of this process, the few (hopfully) that i found harder, due to leak of documentation.

First of all I suggest you to read the official documentation (link)

I have choosen to create a MYSQL instance, since I already had (locally) done it by myself (for a naive school project). Here the offical guide.

Honestly the whole process is well documented, so there is no need to precise anything at all.


Obviously is possible to access directly the DB via prompt shell given by Google itself, however it cannot be used in an application (android).

As you may know android app are normally developed using andorid studio, in java, which actually is our case. So we had the need to access this db using Java.

Obviously ther is the need of the JDBC driver (if you have no idea what im talking about just press here, you should at least be aware of what they are and its use).


Now I could talk about the problems encountered in order to access data in the DB and add data in the DB.

But I don't want to be verbose, so I'll just share with you a mini java program with all (or almost) the instructions useful for read and write operations. You are welcome 😁

// Template program for MySQL DB access and usage w. Java
public static void main(String args[]) throws IOException {
        System.out.println("test");
            try {
								// to import the JDBC driver
								// tou also need to add them to the project libraries (different for each IDE)
                Class.forName("com.mysql.cj.jdbc.Driver");
                Connection con = DriverManager.getConnection(
                        // DB_IP = SQL instance IP
												// DB_PORT = instance port (default should be 3306)
												// DB_NAME = database name
												// USERNAME
												// PSSW = password of the username choosen 
                        "jdbc:mysql://DB_IP:DB_PORT/DB_NAME", "USERNAME", "PSSW ");
                Statement stmt = con.createStatement();

								// example of INSERT command / ADD / REMOVE / ECC...
								String query = "INSERT INTO TableName(att1, att2, att3) VALUES" +
									"('" + att1_value+"', '"+att2_value+"', '"+att3_value+ "')" ;
								// use the syntax " 'varchar_value'" for text, with the single superscript
								// else just the variable for numeric values
                stmt.executeUpdate(query);

                
                //executeQuery to select from tables
                ResultSet rs = stmt.executeQuery("select * from TableName");
								// can add whatever you need to the above query of course

								// to get the attribute for each tuple returned
                while (rs.next())
                    System.out.println(rs.getInt(1) + " \\t " + rs.getString(2) + " \\t\\t " + rs.getString(3) + " \\t\\t " + rs.getString(4));
                con.close();
            } catch (Exception e) {
                System.out.println(e);
            }//Try catch
   }//Main