1

So, Azure has three variants of SQL services:

  1. SQL Database: https://azure.microsoft.com/en-in/services/sql-database/

  2. MySQL: https://azure.microsoft.com/en-in/services/mysql/

  3. PostgreSQL: https://azure.microsoft.com/en-in/services/postgresql/

I can see that there is a Java SDK for the first one. Are there any Java SDKs available for the MySQL/Postgres service APIs?


Maybe this question isn't fit for SO, but wasn't able to get any response on Github issues, so asking it here.

Jatin
  • 14,112
  • 16
  • 49
  • 78

3 Answers3

2

Looking at the source code here, I believe there are no SDKs for MySQL & Postgres database management in Java as of today.

Since SDKs are essentially a wrapper over REST API, one option for you would be to implement REST API yourself till the time support for these come into SDK.

Here are the links to the REST APIs for MySQL & Postgres:

MySQL: https://learn.microsoft.com/en-us/rest/api/mysql/

Postgres: https://learn.microsoft.com/en-us/rest/api/postgresql/

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
1

Azure Java SDK version 1.33.1 doesn't have an inbuilt MySQL management client yet. However, you can use Maven dependency mentioned here

The entry class should be MySQLManager.

Here is a sample code that I have written to create a MySQL server instance using the same client.

@Override
public Server createMySQLServer(AzureTokenCredentials credential,
                                AzureMySqlModel model) {

    if (credential == null || model == null)
        return null;

    Server server = null;
    if (model.validate()) {
        try {
            ServerPropertiesForDefaultCreate defaultProp = new ServerPropertiesForDefaultCreate();

            ServerPropertiesForCreate withVersion = defaultProp.withAdministratorLogin(
                        model.getAdministratorLogin()).withAdministratorLoginPassword(
                                    model.getAdministratorPassword()).withVersion(
                                                model.getServerVersion());

            server = MySQLManager.configure().withLogLevel(
                        LogLevel.BODY).authenticate(credential,
                                    credential.defaultSubscriptionId()).servers().define(
                                                model.getServerName()).withRegion(
                                                            model.getRegion()).withExistingResourceGroup(
                                                                        model.getResourceGroup()).withProperties(
                                                                                    withVersion).create();
        } catch (Exception ex) {
            log.error("Error creating MySQL server {}", ex.getMessage());
        }
    }

    return server;
}

AzureMySqlModel is just a custom Java POJO to get the required details for creating a MySQL server.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Akash jain
  • 19
  • 4
0

Nowadays, both of postgres and mysql was added to Azure SDK

Here, I want to note that both of them have flexible server and those also have different dependencies. Don't repeat my mistake, above dependencies does not work flexible servers.

Akash's answer is also right, but this dependency will become deprecated from next year.

Ulug'bek
  • 2,762
  • 6
  • 31
  • 59