Skip to content

Commit f244863

Browse files
author
Shun Fan
committed
Fix mvm cloud sql sample for local run
1 parent d7f1d7f commit f244863

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

managed_vms/cloudsql/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Before you can run or deploy the sample, you will need to do the following:
2424
1. Set the connection string environment variable in src/main/appengine/app.yaml
2525

2626
## Running locally
27+
Export local variables
28+
$ export SQL_URL="jdbc:mysql://google/YOUR-DB-NAME?cloudSqlInstance=YOUR-INSTANCE-NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=USERNAME&password=PASSWORD"
2729
$ mvn clean jetty:run
2830

2931
## Deploying

managed_vms/cloudsql/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ Copyright 2016 Google Inc. All Rights Reserved.
3737
<scope>provided</scope>
3838
</dependency>
3939
<!-- [START dependencies] -->
40-
<dependency> <!-- http://dev.mysql.com/doc/connector-j/en/ -->
41-
<groupId>mysql</groupId>
42-
<artifactId>mysql-connector-java</artifactId>
43-
<version>6.0.3</version>
44-
</dependency>
4540
<dependency>
4641
<groupId>com.google.cloud.sql</groupId>
4742
<artifactId>mysql-socket-factory</artifactId>

managed_vms/cloudsql/src/main/appengine/app.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ handlers:
2222

2323
# [START env_variables]
2424
env_variables:
25-
SQL_REMOTE_URL: jdbc:mysql://google/YOUR-DB-NAME?cloudSqlInstance=YOUR-INSTANCE-NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=USERNAME&password=PASSWORD
26-
SQL_LOCAL_URL: jdbc:mysql://localhost/YOUR-DB-NAME?user=YOUR-USERNAME&password=PASSWORD&useSSL=false
25+
SQL_URL: jdbc:mysql://google/YOUR-DB-NAME?cloudSqlInstance=YOUR-INSTANCE-NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=USERNAME&password=PASSWORD
2726
# [END env_variables]

managed_vms/cloudsql/src/main/java/com/example/managedvms/cloudsql/CloudSqlServlet.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
6565
PrintWriter out = resp.getWriter();
6666
resp.setContentType("text/plain");
6767
// Detect if running remotely or locally and select correct connection url
68-
String url;
69-
if (System.getenv().containsKey("GAE_MODULE_INSTANCE")) {
70-
url = System.getenv("SQL_REMOTE_URL");
71-
} else {
72-
url = System.getenv("SQL_LOCAL_URL");
73-
}
68+
String url = System.getenv("SQL_URL");
7469

7570
try (Connection conn = DriverManager.getConnection(url);
7671
PreparedStatement statementCreateVisit = conn.prepareStatement(createVisitSql)) {

0 commit comments

Comments
 (0)