|
| 1 | +--- |
| 2 | +title: "Configure the External Database Connector for Databricks" |
| 3 | +linktitle: "Databricks" |
| 4 | +url: /appstore/modules/databricks/external-database-connector/ |
| 5 | +description: "Describes the steps required to use the Mendix External Database connector with Databricks." |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +The [External Database connector](/appstore/modules/external-database-connector/) allows you to connect to databases and select data to use in your app. You can use it to directly test connections and queries during configuration in Studio Pro at design time. For Mendix apps that use Databricks as their database, the External Database connector is the recommended integration option for Mendix 10.20.0 and up. |
| 11 | + |
| 12 | +This how-to describes the steps required to enable your app to use the External Database connector with Databricks. |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +For some general information on how to use bring your own JDBC driver with the external database connector, read [External Database Connector: Configure for Any Database](https://docs.mendix.com/appstore/modules/external-database-connector/#byod). |
| 17 | + |
| 18 | +## Configuring the Connection Between Your Mendix App and Databricks |
| 19 | + |
| 20 | +To connect your Mendix application to Databricks with the External Database connector, follow these steps: |
| 21 | + |
| 22 | +1. Install the [External Database connector](https://marketplace.mendix.com/link/component/219862) version 5.1.1 or higher. |
| 23 | +2. Ensure that you have the required Databricks JDBC Driver by choosing one of the following options: |
| 24 | + |
| 25 | + * To have the dependency downloaded automatically on running your project, add a **Java Dependency** in the **Settings** of you module and provide the following information: |
| 26 | + * **Group ID** - set to **com.databricks** |
| 27 | + * **Artifact ID** - set to **databricks-jdbc** |
| 28 | + * **Version** - set to **2.7.1** |
| 29 | + |
| 30 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/JavaDependency.png" >}} |
| 31 | + |
| 32 | + * To install the dependency manually, download version 2.7.1 of the [JDBC driver](https://www.databricks.com/spark/jdbc-drivers-archive) that Databricks provides and put the .jar file into the *userlib* of your Mendix project. |
| 33 | + |
| 34 | +3. Run you Mendix project and run the [Connect to Database wizard](/appstore/modules/external-database-connector/#configuration), selecting **Other** as the database type. |
| 35 | + |
| 36 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/DatabricksConfig.png" >}} |
| 37 | + |
| 38 | +4. Provide a name for the database connection document. |
| 39 | +5. Enter the following connection details: |
| 40 | + |
| 41 | + * **User name** - set to **token** |
| 42 | + * **Password** - set to the personal access token (PAT) that you can generate through the user settings in Databricks: |
| 43 | + |
| 44 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/PAT.png" >}} |
| 45 | + |
| 46 | +7. In your Databricks account find the JDBC URL related to the SQL warehouse or cluster which you are using. |
| 47 | +8. Copy the URL into the **JDBC URL** field and add *UID=token;PWD=`PAT`*, where `PAT` is your actual PAT. |
| 48 | + |
| 49 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/JDBC_URL.png" >}} |
| 50 | + |
| 51 | +9. Click **Test Connection** to verify the connection details, and then click **Save**. |
| 52 | + |
| 53 | +Your Mendix app now connects to Databricks with the provided connection details. When the connection is successful, you can see your Databricks tables in your Mendix app. |
| 54 | + |
| 55 | +{{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/Database_structure.png" >}} |
| 56 | + |
| 57 | +You can now configure the queries that you need to run on your Databricks database. The following section of this document provides an example of a common query. For general information about creating queries, see [External Database Connector: Querying a Database](/appstore/modules/external-database-connector/#query-database) and [External Database Connector: Using Query Response](/appstore/modules/external-database-connector/#use-query-response). |
| 58 | + |
| 59 | +## Configuring a Basic Query |
| 60 | + |
| 61 | +This section shows a basic example of how to use the database connector to execute a query on your Databricks data. |
| 62 | + |
| 63 | +### Creating Data in your Databricks Workspace |
| 64 | + |
| 65 | +If you do not have any test customer data in your Databricks workspace, you can create it by running the following SQL command in your workspace's SQL Editor: |
| 66 | + |
| 67 | +```sql |
| 68 | +CREATE TABLE customerData ( |
| 69 | + name varchar(64), |
| 70 | + address varchar(64), |
| 71 | + postal_code varchar(6), |
| 72 | + gender varchar(64) |
| 73 | +); |
| 74 | + |
| 75 | +INSERT INTO customerData (name, address, postal_code, gender) VALUES |
| 76 | + ('Henk de Vries', 'Klaprooslaan 5, Bloemenstad', '1234AB', 'Male'), |
| 77 | + ('Sanne Verbeek', 'Molendam 8, Waterveen', '2345CD', 'Female'), |
| 78 | + ('Jan-Willem Bos', 'Zonstraat 22, Zomerhoven', '3456EF', 'Male'), |
| 79 | + ('Marieke de Groot', 'Windmolenweg 33, Korenveld', '4567GH', 'Female'), |
| 80 | + ('Bert van Dijk', 'Vlinderplein 15, Lenteveen', '5678JK', 'Male'), |
| 81 | + ('Lotte van Dam', 'Regenboogpad 10, Kleurenburg', '6789LM', 'Female'), |
| 82 | + ('Koen Smits', 'Eikenlaan 2, Bosrijk', '7890NO', 'Male'), |
| 83 | + ('Emma Visser', 'Druppelweg 45, Regenstad', '8901QP', 'Female'), |
| 84 | + ('Thomas Mulder', 'Sterrenhof 7, Hemelrijk', '9012RS', 'Male'), |
| 85 | + ('Sophie Jansen', 'Kersenstraat 12, Fruitdorp', '0123TU', 'Female'); |
| 86 | +``` |
| 87 | + |
| 88 | +{{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/SQL_Editor.png" >}} |
| 89 | + |
| 90 | +### Querying the Data |
| 91 | + |
| 92 | +After you have created a table with some entries, you can now be query from your Mendix application. |
| 93 | + |
| 94 | +1. In your Mendix app, in the **App Explorer**, find and open the external connection document that you created with the Connect to Database wizard. |
| 95 | +2. In the **Name** field, enter a name for your query, for example, *CustomerData_Get*. |
| 96 | +3. Enter the following **SQL Query**: |
| 97 | + |
| 98 | + ```sql |
| 99 | + SELECT * FROM customerData |
| 100 | + ``` |
| 101 | + |
| 102 | +4. Click **Run Query**. |
| 103 | + |
| 104 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/Query.png" >}} |
| 105 | + |
| 106 | +5. Verify that the results are correct, and then generate the required entity to collect the data in your Mendix application. For more information, see [External Database Connector: Creating an Entity from the Response](/appstore/modules/external-database-connector/#create-entity). |
| 107 | +6. Create a microflow that will run the query by doing the following steps: |
| 108 | + 1. In the **App Explorer**, right-click on the name of your module, and then click **Add microflow**. |
| 109 | + 2. Enter a name for your microflow, for example, *ACT_Customerdata_Get*, and then click **OK**. |
| 110 | + 3. In your **Toolbox**, find the **Query External Database** activity and drag it onto the work area of your microflow. |
| 111 | + 4. Position the **Query External Database** activity between the start and end event of your microflow. |
| 112 | + 5. Double-click the **Query External Database** microflow activity to configure the required parameters. |
| 113 | + 6. In the **Database** section, select your Databricks database. |
| 114 | + 7. In the **Query** list, select the query name that you entered in step 2. |
| 115 | + 10. In the **Output** section, provide the following values: |
| 116 | + * **Return type** - **List of *{your module name}*.customerdata** |
| 117 | + * **Use return value** - set to **Yes** |
| 118 | + * **List name** - enter *Customerdata_list* |
| 119 | + 11. Click **OK**. |
| 120 | + |
| 121 | + {{< figure src="/attachments/appstore/platform-supported-content/modules/databricks/JA_Query.png" >}} |
| 122 | + |
| 123 | +7. Link the microflow to a microflow button and use the Debugger to test if the objects are properly returned. |
0 commit comments