Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 2.39 KB

File metadata and controls

55 lines (41 loc) · 2.39 KB
title Azure Database for MySQL libraries for Java
description Reference documentation for the Java client libraries for Azure Database for MySQL
keywords Azure, Java, SDK, API, SQL, database, PostGres, MySQL
author rloutlaw
ms.author routlaw
manager douge
ms.date 05/17/2017
ms.topic article
ms.devlang java
ms.service mysql

Azure Database for MySQL libraries for Java

Overview

Azure Database for MySQL is a relational database service based on the open source MySQL Server engine.

To get started with Azure Database for MySQL, see Use Java to connect and query data.

Client JBDC driver

Connect to Azure Database for MySQL from your applications using the open-source MySQL JDBC driver. You can use the Java JDBC API to directly connect to the database or use data access frameworks that interact with the database through JDBC such as Hibernate.

Add a dependency to your Maven pom.xml file to use the client JDBC driver in your project.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.42</version>
</dependency>

Example

Connect to Azure Database for MySQL using JDBC and select all records in the sales table. You can get the JDBC connection string for the database from the Azure Portal.

String url = String.format("jdbc:mysql://fabrikamysql.mysql.database.azure.com:3306/fabrikamdb?verifyServerCertificate=true&useSSL=true&requireSSL=false");
try {
    Connection conn = DriverManager.getConnection(url, "frank@fabrikamysql", "aBcDeFgHiJkL");
    String selectSql = "SELECT * FROM SALES";
    Statement statement = conn.createStatement();
    ResultSet resultSet = statement.executeQuery(selectSql);
}

Samples

Build a Java and MySQL web app
Design a MySQL database using the Azure CLI

Explore more sample Java code for Azure Database for MySQL you can use in your apps.