Skip to content

Commit

Permalink
Merge pull request #278 from GoogleCloudPlatform/cloudsql
Browse files Browse the repository at this point in the history
Fix mvm cloud sql sample for local run
  • Loading branch information
Shun Fan authored Jul 29, 2016
2 parents d7f1d7f + f244863 commit ebdad96
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
2 changes: 2 additions & 0 deletions managed_vms/cloudsql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Before you can run or deploy the sample, you will need to do the following:
1. Set the connection string environment variable in src/main/appengine/app.yaml

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

## Deploying
Expand Down
5 changes: 0 additions & 5 deletions managed_vms/cloudsql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ Copyright 2016 Google Inc. All Rights Reserved.
<scope>provided</scope>
</dependency>
<!-- [START dependencies] -->
<dependency> <!-- http://dev.mysql.com/doc/connector-j/en/ -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions managed_vms/cloudsql/src/main/appengine/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ handlers:

# [START env_variables]
env_variables:
SQL_REMOTE_URL: jdbc:mysql://google/YOUR-DB-NAME?cloudSqlInstance=YOUR-INSTANCE-NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=USERNAME&password=PASSWORD
SQL_LOCAL_URL: jdbc:mysql://localhost/YOUR-DB-NAME?user=YOUR-USERNAME&password=PASSWORD&useSSL=false
SQL_URL: jdbc:mysql://google/YOUR-DB-NAME?cloudSqlInstance=YOUR-INSTANCE-NAME&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=USERNAME&password=PASSWORD
# [END env_variables]
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
PrintWriter out = resp.getWriter();
resp.setContentType("text/plain");
// Detect if running remotely or locally and select correct connection url
String url;
if (System.getenv().containsKey("GAE_MODULE_INSTANCE")) {
url = System.getenv("SQL_REMOTE_URL");
} else {
url = System.getenv("SQL_LOCAL_URL");
}
String url = System.getenv("SQL_URL");

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

0 comments on commit ebdad96

Please sign in to comment.