Creation of a MySQL DB (in cloud) using a Google Cloud SQL instance (+ Java code)

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.

Here a breif description on my Notion, hope you like it 😁

Useful Java Code for MySQL db in Google Cloud SQL instance interaction:

// 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

Some of my posts:

Kingdom of the Planet of the Apes – Trailer

John Wick 5 – Trailer

Quote #1

Pyhton – Loop Videos & Add Audio track

Number and Stats about the Universe

The Solar System

OpenAI says new model GPT-4 is more creative and less likely to invent facts

Try out ChatGPT

Google’s AI generator creates HD video from text !!!

YOLOv7: The Fastest Object Detection Algorithm (2022)

AI-Generated Artwork Wins State Fair Competition, Leaving Human Artists Unhappy

Transfer Learning with Python – Tensorflow

GitHub update : New Repo with all my Tests !!

Tesla Model S Plaid : INSANE !

Turn in Norway: a self-driving bus goes into service!

Microsoft lauched project to train drone AI systems – AirSim

Life in the Universe: What are the Odds?

MY SetUp(IT) – UPDATE

My New York Times telegam channel is LIVE!! 🗞️🗞️

LaMDA: GOOGLE breakthrough conversation technology

Useful links: