@@ -65,10 +65,28 @@ await connection.OpenAsync();
65
65
1. Get the connection string from the environment variable, and add the plugin name to connect to the database:
66
66
67
67
```java
68
- String url = System.getenv("AZURE_MYSQL_CONNECTIONSTRING");
68
+ String url = System.getenv("AZURE_MYSQL_CONNECTIONSTRING");
69
69
String pluginName = "com.azure.identity.extensions.jdbc.mysql.AzureMysqlAuthenticationPlugin";
70
- Connection connection = DriverManager.getConnection(url + "& defaultAuthenticationPlugin=" +
71
- pluginName + "& authenticationPlugins=" + pluginName);
70
+
71
+ Properties properties = new Properties();
72
+ properties.put("defaultAuthenticationPlugin", pluginName);
73
+ properties.put("authenticationPlugins", pluginName);
74
+
75
+ // Uncomment the following lines corresponding to the authentication type you want to use.
76
+
77
+ // for user-assigned managed identity
78
+ // String clientId = System.getenv('AZURE_MYSQL_CLIENTID')
79
+ // properties.put("azure.clientId","${YOUR_CLIENT_ID}");
80
+
81
+ // For service principal
82
+ // String tenantId = System.getenv('AZURE_MYSQL_TENANTID')
83
+ // String clientId = System.getenv('AZURE_MYSQL_CLIENTID')
84
+ // String clientSecret = System.getenv('AZURE_MYSQL_CLIENTSECRET')
85
+ // properties.put("azure.clientId","${YOUR_CLIENT_ID}");
86
+ // properties.put("azure.clientSecret","${YOUR_CLIENT_SECRET}");
87
+ // properties.put("azure.tenantId","${YOUR_TENANT_ID}");
88
+
89
+ Connection connection = DriverManager.getConnection(url, properties);
72
90
```
73
91
74
92
For more information, see [Use Java and JDBC with Azure Database for MySQL - Flexible Server](/azure/mysql/flexible-server/connect-java?tabs=passwordless).
0 commit comments