Environment:
- Google cloud App Engine standard environment
- Google Cloud sql database instance (mysql)
Installation Steps:
- Java web application war file is deployed using App Engine Java SDK 1.9.62 using appcfg update command
- Jar files installed as part of the deployment on google cloud: mysql-connector-java-5.1.38.jar mysql-socket-factory-1.0.4.jar mysql-socket-factory-cor-1.0.2.jar jdbc-socket-factory-core-1.0.5.jar
JDBC connection steps using Java:
try {
//DriverManager.registerDriver(com.mysql.jdbc.Driver);
String DBUrl = String.format("jdbc:mysql://google/%s?cloudSqlInstance=%s&"
+ "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
databaseName,instanceConnectionName);
Connection DbConn = DriverManager.getConnection(DBUrl,DBUser,DBPwd);
} catch(SQLException ex) {
System.out.println("Database Connection Error."+ex.getMessage());
}
Steps for error message:
Open application using project-id.appspot.com
Following Error Message: 16-0 Could not create connection to database server.
Steps followed for Database Verification on local server:
JDBC connection steps using Java:
try {
// -- Use cloud sql remote ip address say x.x.x.x
String DBUrl = String.format("jdbc:mysql://x.x.x.x:3306/%s",databaseName);
Connection DbConn = DriverManager.getConnection(DBUrl,DBUser,DBPwd);
} catch(SQLException ex) {
System.out.println("Database Connection Error."+ex.getMessage());
}
- JDBC remote connection to Gloud Cloud mysql database using above steps
- Run java web application on Windows
- Application is working fine.
I spent two days and tried various steps, the same error is displayed. Any ideas how to resolve the issue, or where is the problem.