Skip to content

Commit c1d5266

Browse files
authored
Merge pull request #102825 from WilliamAntonRohm/quickstarts-mysql
Quickstart consistency - MySQL connectors
2 parents c75e3e7 + 8dbc0e8 commit c1d5266

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

articles/mysql/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
href: connect-php.md
2222
- name: Java
2323
href: connect-java.md
24-
- name: .Net
24+
- name: .NET
2525
href: connect-csharp.md
2626
- name: Python
2727
href: connect-python.md

articles/mysql/connect-java.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@ ms.date: 12/02/2019
1212

1313
# Quickstart: Use Java to connect to and query data in Azure Database for MySQL
1414

15-
This quickstart demonstrates how to connect to an Azure Database for MySQL by using a Java application and the JDBC driver [MariaDB Connector/J](https://mariadb.com/kb/en/library/mariadb-connector-j/). It shows how to use SQL statements to query, insert, update, and delete data in the database. This article assumes that you are familiar with developing using Java and that you are new to working with Azure Database for MySQL.
15+
In this quickstart, you connect to an Azure Database for MySQL by using a Java application and the JDBC driver MariaDB Connector/J. You then use SQL statements to query, insert, update, and delete data in the database from Mac, Ubuntu Linux, and Windows platforms.
16+
17+
This topic assumes that you're familiar with developing using Java, but you're new to working with Azure Database for MySQL.
1618

1719
## Prerequisites
18-
1. This quickstart uses the resources created in either of these guides as a starting point:
19-
- [Create an Azure Database for MySQL server using Azure portal](./quickstart-create-mysql-server-database-using-azure-portal.md)
20-
- [Create an Azure Database for MySQL server using Azure CLI](./quickstart-create-mysql-server-database-using-azure-cli.md)
2120

22-
2. Ensure your Azure Database for MySQL connection security is configured with the firewall opened and SSL settings adjusted for your application to connect successfully.
21+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
22+
- An Azure Database for MySQL server. [Create an Azure Database for MySQL server using Azure portal](quickstart-create-mysql-server-database-using-azure-portal.md) or [Create an Azure Database for MySQL server using Azure CLI](quickstart-create-mysql-server-database-using-azure-cli.md).
23+
- Azure Database for MySQL connection security is configured with the firewall opened and SSL connection settings configured for your application.
24+
25+
## Obtain the MariaDB connector
2326

24-
3. Obtain the MariaDB Connector/J connector using one of the following approaches:
27+
Obtain the [MariaDB Connector/J](https://mariadb.com/kb/en/library/mariadb-connector-j/) connector using one of the following approaches:
2528
- Use the Maven package [mariadb-java-client](https://search.maven.org/search?q=a:mariadb-java-client) to include the [mariadb-java-client dependency](https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client) in the POM file for your project.
26-
- Download the JDBC driver [MariaDB Connector/J](https://downloads.mariadb.org/connector-java/) and include the JDBC jar file (for example mariadb-java-client-2.4.3.jar) into your application classpath. If you have trouble with classpaths, consult your environment's documentation for class path specifics, such as [Apache Tomcat](https://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html) or [Java SE](https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html)
29+
- Download the JDBC driver [MariaDB Connector/J](https://downloads.mariadb.org/connector-java/) and include the JDBC jar file (for example mariadb-java-client-2.4.3.jar) into your application class path. Consult your environment's documentation for class path specifics, such as [Apache Tomcat](https://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html) or [Java SE](https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html)
2730

2831
## Get connection information
32+
2933
Get the connection information needed to connect to the Azure Database for MySQL. You need the fully qualified server name and login credentials.
3034

3135
1. Log in to the [Azure portal](https://portal.azure.com/).
@@ -35,6 +39,7 @@ Get the connection information needed to connect to the Azure Database for MySQL
3539
![Azure Database for MySQL server name](./media/connect-java/azure-database-mysql-server-name.png)
3640

3741
## Connect, create table, and insert data
42+
3843
Use the following code to connect and load the data using the function with an **INSERT** SQL statement. The [getConnection()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#using-drivermanager) method is used to connect to MySQL. Methods [createStatement()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#creating-a-table-on-a-mariadb-or-mysql-server) and execute() are used to drop and create the table. The prepareStatement object is used to build the insert commands, with setString() and setInt() to bind the parameter values. Method executeUpdate() runs the command for each set of parameters to insert the values.
3944

4045
Replace the host, database, user, and password parameters with the values that you specified when you created your own server and database.
@@ -137,6 +142,7 @@ public class CreateTableInsertRows {
137142
```
138143

139144
## Read data
145+
140146
Use the following code to read the data with a **SELECT** SQL statement. The [getConnection()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#using-drivermanager) method is used to connect to MySQL. Methods [createStatement()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#creating-a-table-on-a-mariadb-or-mysql-server) and executeQuery() are used to connect and run the select statement. The results are processed using a ResultSet object.
141147

142148
Replace the host, database, user, and password parameters with the values that you specified when you created your own server and database.
@@ -224,6 +230,7 @@ public class ReadTable {
224230
```
225231

226232
## Update data
233+
227234
Use the following code to change the data with an **UPDATE** SQL statement. The [getConnection()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#using-drivermanager) method is used to connect to MySQL. The methods [prepareStatement()](https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) and executeUpdate() are used to prepare and run the update statement.
228235

229236
Replace the host, database, user, and password parameters with the values that you specified when you created your own server and database.
@@ -306,6 +313,7 @@ public class UpdateTable {
306313
```
307314

308315
## Delete data
316+
309317
Use the following code to remove data with a **DELETE** SQL statement. The [getConnection()](https://mariadb.com/kb/en/library/about-mariadb-connector-j/#using-drivermanager) method is used to connect to MySQL. The methods [prepareStatement()](https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) and executeUpdate() are used to prepare and run the delete statement.
310318

311319
Replace the host, database, user, and password parameters with the values that you specified when you created your own server and database.

articles/mysql/connect-nodejs.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ ms.topic: quickstart
1010
ms.date: 12/02/2019
1111
---
1212
# Quickstart: Use Node.js to connect and query data in Azure Database for MySQL
13-
This quickstart demonstrates how to connect to an Azure Database for MySQL using [Node.js](https://nodejs.org/) from Windows, Ubuntu Linux, and Mac platforms. It shows how to use SQL statements to query, insert, update, and delete data in the database. This topic assumes that you are familiar with developing using Node.js and that you are new to working with Azure Database for MySQL.
13+
14+
In this quickstart, you connect to an Azure Database for MySQL by using Node.js. You then use SQL statements to query, insert, update, and delete data in the database from Mac, Ubuntu Linux, and Windows platforms.
15+
16+
This topic assumes that you're familiar with developing using Node.js, but you're new to working with Azure Database for MySQL.
1417

1518
## Prerequisites
16-
This quickstart uses the resources created in either of these guides as a starting point:
17-
- [Create an Azure Database for MySQL server using Azure portal](./quickstart-create-mysql-server-database-using-azure-portal.md)
18-
- [Create an Azure Database for MySQL server using Azure CLI](./quickstart-create-mysql-server-database-using-azure-cli.md)
1919

20-
You also need to:
21-
- Install the [Node.js](https://nodejs.org) runtime.
22-
- Install [mysql](https://www.npmjs.com/package/mysql) package to connect to MySQL from the Node.js application.
20+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
21+
- An Azure Database for MySQL server. [Create an Azure Database for MySQL server using Azure portal](quickstart-create-mysql-server-database-using-azure-portal.md) or [Create an Azure Database for MySQL server using Azure CLI](quickstart-create-mysql-server-database-using-azure-cli.md).
2322

2423
## Install Node.js and the MySQL connector
25-
Depending on your platform, follow the instructions in the appropriate section to install Node.js. Use npm to install the mysql package and its dependencies into your project folder.
24+
25+
Depending on your platform, follow the instructions in the appropriate section to install [Node.js](https://nodejs.org). Use npm to install the [mysql](https://www.npmjs.com/package/mysql) package and its dependencies into your project folder.
2626

2727
### **Windows**
28+
2829
1. Visit the [Node.js downloads page](https://nodejs.org/en/download/), and then select your desired Windows installer option.
2930
2. Make a local project folder such as `nodejsmysql`.
3031
3. Open the command prompt, and then change directory into the project folder, such as `cd c:\nodejsmysql\`
@@ -39,6 +40,7 @@ Depending on your platform, follow the instructions in the appropriate section t
3940
5. Verify the installation by checking the `npm list` output text. The version number may vary as new patches are released.
4041

4142
### **Linux (Ubuntu)**
43+
4244
1. Run the following commands to install **Node.js** and **npm** the package manager for Node.js.
4345

4446
```bash
@@ -56,6 +58,7 @@ Depending on your platform, follow the instructions in the appropriate section t
5658
3. Verify the installation by checking npm list output text. The version number may vary as new patches are released.
5759

5860
### **Mac OS**
61+
5962
1. Enter the following commands to install **brew**, an easy-to-use package manager for Mac OS X and **Node.js**.
6063

6164
```bash
@@ -74,6 +77,7 @@ Depending on your platform, follow the instructions in the appropriate section t
7477
3. Verify the installation by checking the `npm list` output text. The version number may vary as new patches are released.
7578

7679
## Get connection information
80+
7781
Get the connection information needed to connect to the Azure Database for MySQL. You need the fully qualified server name and login credentials.
7882

7983
1. Log in to the [Azure portal](https://portal.azure.com/).
@@ -83,12 +87,14 @@ Get the connection information needed to connect to the Azure Database for MySQL
8387
![Azure Database for MySQL server name](./media/connect-nodejs/server-name-azure-database-mysql.png)
8488

8589
## Running the JavaScript code in Node.js
90+
8691
1. Paste the JavaScript code into text files, and then save it into a project folder with file extension .js (such as C:\nodejsmysql\createtable.js or /home/username/nodejsmysql/createtable.js).
8792
2. Open the command prompt or bash shell, and then change directory into your project folder `cd nodejsmysql`.
8893
3. To run the application, enter the node command followed by the file name, such as `node createtable.js`.
8994
4. On Windows, if the node application is not in your environment variable path, you may need to use the full path to launch the node application, such as `"C:\Program Files\nodejs\node.exe" createtable.js`
9095

9196
## Connect, create table, and insert data
97+
9298
Use the following code to connect and load the data by using **CREATE TABLE** and **INSERT INTO** SQL statements.
9399

94100
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) function is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) function is used to execute the SQL query against MySQL database.
@@ -156,6 +162,7 @@ function queryDatabase(){
156162
```
157163

158164
## Read data
165+
159166
Use the following code to connect and read the data by using a **SELECT** SQL statement.
160167

161168
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database. The results array is used to hold the results of the query.
@@ -208,6 +215,7 @@ function readData(){
208215
```
209216

210217
## Update data
218+
211219
Use the following code to connect and read the data by using an **UPDATE** SQL statement.
212220

213221
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database.
@@ -256,6 +264,7 @@ function updateData(){
256264
```
257265

258266
## Delete data
267+
259268
Use the following code to connect and read the data by using a **DELETE** SQL statement.
260269

261270
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database.
@@ -304,5 +313,6 @@ function deleteData(){
304313
```
305314

306315
## Next steps
316+
307317
> [!div class="nextstepaction"]
308318
> [Migrate your database using Export and Import](./concepts-migrate-import-export.md)

0 commit comments

Comments
 (0)