Code Monkey home page Code Monkey logo

spring-data-jpa-on-azure's Introduction

page_type description languages products urlFragment
sample
This sample shows how to use Spring Data JPA module with different Azure Database services.
java
azure
spring-jpa-azure

Spring Data JPA on Azure

This sample shows how to use Spring Data JPA module with different Azure Database services.

TOC

Prerequisites

  • Azure Account
  • JDK 1.8 or above
  • Maven 3.0 or above
  • Curl
  • Database Client
    • MySQL CLI
    • pgAdmin for PostgreSQL

Build and Package

You can build this sample with different Azure Database services. SQL Server, MySQL and PostgreSQL are supported by Azure. Follow below sections to use one of them.

Azure Database for MySQL

  1. Create an Azure Database for MySQL server by following tutorial at here.

  2. Configure a firewall rule to allow your machine accessing the created MySQL server by following tutorial at here.

  3. Use mysql to connect to your MySQL server and create a database named mysqldb by following tutorial at here.

  4. Find application.properties at src/main/resources directory and fill in below properties.

    spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
    
    spring.datasource.url=<replace with your database server URL>
    spring.datasource.username=<replace with your database server username>
    spring.datasource.password=<replace with your database server password>
    

    NOTE spring.datasource.url should be in the form of jdbc:mysql://<MySQL Host>:3306/mysqldb?useSSL=true&requireSSL=false

  5. Package the sample application by running below command.

    mvn package -P mysql

Azure Database for PostgreSQL

  1. Create an Azure Database for PostgreSQL server by following tutorial at here.

  2. Configure a firewall rule to allow your machine accessing the created PostgreSQL server by following tutorial at here.

  3. Use pgAdmin to connect to your PostgreSQL server and create a database named mypgsqldb by following tutorial at here.

  4. Find application.properties at src/main/resources directory and fill in below properties.

    spring.datasource.url=<replace with your database server URL>
    spring.datasource.username=<replace with your database server username>
    spring.datasource.password=<replace with your database server password>
    

    NOTE spring.datasource.url should be in the form of jdbc:postgresql://<PostgreSQL Host>:5432/mypgsqldb?ssl=true&sslmode=prefer

  5. Package the sample application by running below command.

    mvn package -P postgresql

Azure SQL Database

  1. Create an Azure SQL Database by following tutorial at here.

  2. Create a firewall rule to allow your machine accessing the created Azure SQL Database by following tutorial at here.

  3. Find application.properties at src/main/resources directory and fill in below properties.

    spring.datasource.url=<replace with your database server URL>
    spring.datasource.username=<replace with your database server username>
    spring.datasource.password=<replace with your database server password>
    

    NOTE spring.datasource.url should be in the form of jdbc:sqlserver://{SQL Host}:1433;database=sqldb;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;

  4. Package the sample application by running below command.

    mvn clean package -P sql

Run

Following below steps to run and test the sample application.

  1. Run application.

    java -jar target/spring-data-jpa-on-azure-0.1.0-SNAPSHOT.jar
  2. Create new users by running below command.

    curl -s -d '{"name":"Tom","species":"cat"}' -H "Content-Type: application/json" -X POST http://localhost:8080/pets
    curl -s -d '{"name":"Jerry","species":"mouse"}' -H "Content-Type: application/json" -X POST http://localhost:8080/pets

    Sample output is as below.

    Added Pet(id=1, name=Tom, species=cat).
    ...
    Added Pet(id=2, name=Jerry, species=mouse).
    
  3. Get all existing pets by running below command.

    curl -s http://localhost:8080/pets

    Sample output is as below.

    [{"id":1,"name":"Tom","species":"cat"},{"id":2,"name":"Jerry","species":"mouse"}]

spring-data-jpa-on-azure's People

Contributors

msftgits avatar supernova-eng avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-data-jpa-on-azure's Issues

Unknown system variable 'query_cache_size'

I am following instructions to connect to Azure Database for MySQL (Version 8.0).

Getting following error when running java -jar target/spring-data-jpa-on-azure-0.1.0-SNAPSHOT.jar

java.sql.SQLException: Unknown system variable 'query_cache_size' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2491) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2449) ~[mysql-connector-java-5.1.47.jar!/:5.1.47] at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381) ~[mysql-connector-java-5.1.47.jar!/:5.1.47]

What changes are needed to make this work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.