You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Create a function app for .NET, JavaScript, TypeScriptor Python.
129
+
2. Create a function app for .NET, JavaScript, TypeScript, Python, or Java.
126
130
127
131
**.NET**
128
132
```bash
@@ -154,6 +158,13 @@ These steps can be done in the Terminal/CLI or with PowerShell.
154
158
func init --worker-runtime python
155
159
```
156
160
161
+
**Java**
162
+
```bash
163
+
mkdir MyApp
164
+
cd MyApp
165
+
func init --worker-runtime java
166
+
```
167
+
157
168
3. Enable SQL bindings on the functionapp. More information can be found [in Microsoft Docs](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql).
158
169
159
170
**.NET:** Install the extension.
@@ -190,6 +201,24 @@ These steps can be done in the Terminal/CLI or with PowerShell.
190
201
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
191
202
```
192
203
204
+
**Java:**
205
+
Update the `host.json` file to the preview extension bundle.
Once you have your Function App you need to configure it for use with Azure SQL bindings for Azure Functions.
@@ -565,6 +594,132 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
565
594
- Hit 'F5' to run your code. Click the link to upsert the output array values in your SQL table. Your upserted values should launch in the browser.
566
595
- Congratulations! You have successfully created your first SQL output binding! Checkout [Output Binding](#Output-Binding) for more information on how to use it and explore on your own!
567
596
597
+
### Java functions
598
+
599
+
#### Input Binding Tutorial
600
+
601
+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server).
602
+
603
+
- Open your app that you created in [Create a Function App](#create-a-function-app) in VSCode
604
+
- Press 'F1' and search for 'Azure Functions: Create Function'
605
+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
606
+
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
*In the above, "select * from Employees" is the SQL script run by the input binding. The CommandType on the line below specifies whether the first line is a query or a stored procedure. On the next line, the ConnectionStringSetting specifies that the app setting that contains the SQL connection string used to connect to the database is "SqlConnectionString." For more information on this, see the [Input Binding](#Input-Binding) section*
- Open the local.settings.json file, and in the brackets for "Values," verify there is a 'SqlConnectionString.' If not, add it.
683
+
- Hit 'F5' to run your code. This will start up the Functions Host with a local HTTP Trigger and SQL Input Binding.
684
+
- Click the link that appears in your terminal.
685
+
- You should see your database output in the browser window.
686
+
- Congratulations! You have successfully created your first SQL input binding! Checkout [Input Binding](#Input-Binding) for more information on how to use it and explore on your own!
687
+
688
+
#### Output Binding Tutorial
689
+
690
+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server), and that you have the 'Employee.java' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
691
+
692
+
- Open your app in VSCode
693
+
- Press 'F1' and search for 'Azure Functions: Create Function'
694
+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
695
+
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
696
+
697
+
```java
698
+
public HttpResponseMessage run(
699
+
@HttpTrigger(
700
+
name = "req",
701
+
methods = {HttpMethod.GET},
702
+
authLevel = AuthorizationLevel.ANONYMOUS,
703
+
route = "addemployees-array")
704
+
HttpRequestMessage<Optional<String>> request,
705
+
@SQLOutput(
706
+
commandText = "dbo.Employees",
707
+
connectionStringSetting = "SqlConnectionString")
708
+
OutputBinding<Employee[]> output) {
709
+
output = new Employee[]
710
+
{
711
+
new Employee(1, "Hello", "World", "Microsoft", "Functions"),
712
+
new Employee(2, "Hi", "SQLupdate", "Microsoft", "Functions")
*In the above, "dbo.Employees" is the name of the table our output binding is upserting into. The line below is similar to the input binding and specifies where our SqlConnectionString is. For more information on this, see the [Output Binding](#Output-Binding) section*
719
+
720
+
- Hit 'F5' to run your code. Click the link to upsert the output array values in your SQL table. Your upserted values should launch in the browser.
721
+
- Congratulations! You have successfully created your first SQL output binding! Checkout [Output Binding](#Output-Binding) for more information on how to use it and explore on your own!
722
+
568
723
## Configuration
569
724
570
725
This section goes over some of the configuration values you can use to customize the SQL bindings. See [How to Use Azure Function App Settings](https://learn.microsoft.com/azure/azure-functions/functions-how-to-use-azure-function-app-settings) to learn more.
0 commit comments