Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringCloud_GCP_Cloud-SQL-DB

Google Cloud Configuration for the project

1. You can utilize the Google cloud free tier or you can use your gcloud to get access.

Google cloud free tier

2. Once you active your account you can create new project or use existing project.

3. you need to create SQL instance.

you can use search bar or menu to find the SQL

4. It might take while to configure the instance.

5. we need to enable API access for your account.

5.1 you can search the API using Platform search bar Cloud SQL Admin API. you have enable this API service to access the DATABASE.

6. Last we need to create server account to access the services with secure and authenticate credentials by Creating Service Account for SQL admin access.

6.1 IAM & Admin > service Accounts >

6.2 Create Service Account

6.3 assign access permission as SQL admin

6.4 create a key

6.5 Json ( we need to add the path of the location to Project application.properties file)

Application configuration to access the Gcloud

#Project name in Gcloud
spring.cloud.gcp.project-id=springcloud-data-sql
# SQL instance connection name 
spring.cloud.gcp.sql.instance-connection-name=springcloud-data-sql:australia-southeast1:sada-postgresql-instance 
#Databae name
spring.cloud.gcp.sql.database-name=postgres

spring.datasource.username=postgres
#password
spring.datasource.password=sada
#Json credentials to access the gloud account.
spring.cloud.gcp.credentials.location=file:/Users/X270/Desktop/springcloud-data-sql-95f7ceb8e5ec.json
spring.jpa.generate-ddl=true

once you configure the all the details in application.properties file.

Start the application

mvn spring-boot:run 

Once the application running without problems.You send Post request by using Postman

After sending the Post request you can check the Database table in by using Gcloud shell.

SQL > Click on your instance > connect using cloud shell

 gcloud sql connect sada-postgresql-instance --user=postgres --quiet

Enter your password

To access the postgres db

  \c postgres

**Enter your password **

To see the list of tables in DB.

   \dt

Check the data added to table or not

select * from product;

OR you can write simple test case to get the data from Gcloud DB table.

@Test
	public void testProduct(){
		List<Product> a=productRepository.findAll();
		for(Product product : a){
			//System.out.println(product.getId());
			System.out.println("Tesla Model: "+ product.getName());
			System.out.println("Tesla Price: "+ product.getPrice());
			System.out.println("Warehouse:   "+   product.getWarehouse());
			System.out.println("-------------------------------------");
		} 

Done :)

About

SpringCloud_GCP_Cloud SQL database

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages