Currently, I have created a simple Java application that connects to my Google Cloud SQL database the normal way:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://-google-cloud-sql-ip:-port-/-projectname-","-user-","-password-");
Statement st = con.createStatement();
}
catch (Exception ex) {
ex.printStackTrace();
}
My only concern is that the password is placed here as plain text. It is not protected in any way. I do know that it is possible to protect the source code with something like yGuard. Also, I have to register my external IP address in Google Cloud for it to work.
Therefore, I was wondering if I could use some sort of OAuth method to make a database connection to the Cloud SQL database. I'd prefer a connection method that is independent of my computer's physical location, so I can connect anywhere I want (if I have an internet connection).
Is there a better method than the one presented above, or is this the only way? And if so, please let me know how to protect the plain text password.
Any help is much appreciated!