GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docs-samples/appengine-java11/cloudsql at main · faube/java-docs-samples

Expand file tree

/

cloudsql

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

cloudsql

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
app.yaml
app.yaml
 
 
pom.xml
pom.xml
 
 

README.md

Outline

Connecting to Cloud SQL - MySQL with Java 11 on Google App Engine Standard

This sample demonstrates how to use Cloud SQL - MySQL on Google App Engine Standard.

Code

The sample code is located in java-docs-samples/cloud-sql/mysql/servlet. This directory has the supplemental files needed to deploy to Google App Engine Standard with Java 11.

Setup your Cloud SQL Database

  • Create a 2nd Gen Cloud SQL Instance by following these instructions. Note the connection string, database user, and database password that you create.

  • Create a database for your application by following these instructions. Note the database name.

  • Create a service account with the 'Cloud SQL Client' permissions by following these instructions. Download a JSON key to use to authenticate your connection.

Setup the App

  • See Prerequisites.

  • Add the appengine-simple-jetty-main Main class to your classpath:

  cd java-docs-samples/appengine-java11/appengine-simple-jetty-main
  mvn install
  • Move into the sample directory:
cd ../../cloud-sql/mysql/servlet/
  • In the new Java 11 runtime, you must remove your appengine-web.xml file and create an app.yaml file to configure your application settings. Create an src/main/appengine directory and copy the app.yaml provided:
mkdir src/main/appengine
cp ../../../appengine-java11/cloudsql/app.yaml src/main/appengine/
  • Use the information from creating your database to replace the environment variables in your app.yaml:
CLOUD_SQL_CONNECTION_NAME: '<MY-PROJECT>:<INSTANCE-REGION>:<MY-DATABASE>'
DB_NAME: 'my_db'
DB_USER: 'my-db-user'
DB_PASS: 'my-db-pass'
  • Java 11 has specific requirements on packaging your app. Replace the pom.xml with the Java 11 pom.xml:
cp ../../../appengine-java11/cloudsql/pom.xml ./

Deploy to Google Cloud

The following command will deploy the application to your Google Cloud project:

mvn clean package appengine:deploy -DskipTests

View your application:

gcloud app browse

or by visiting https://<your-project-id>.appspot.com.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.