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.
105
+
2. Create a function app for .NET, JavaScript, TypeScript, Python, or Java.
104
106
105
107
**.NET**
106
108
```bash
@@ -132,6 +134,13 @@ These steps can be done in the Terminal/CLI or with PowerShell.
132
134
func init --worker-runtime python
133
135
```
134
136
137
+
**Java**
138
+
```bash
139
+
mkdir MyApp
140
+
cd MyApp
141
+
func init --worker-runtime java
142
+
```
143
+
135
144
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).
136
145
137
146
**.NET:** Install the extension.
@@ -167,6 +176,24 @@ These steps can be done in the Terminal/CLI or with PowerShell.
167
176
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
168
177
```
169
178
179
+
**Java:**
180
+
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.
@@ -502,6 +529,148 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
502
529
- 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.
503
530
- 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!
504
531
532
+
### Java functions
533
+
534
+
#### Input Binding Tutorial
535
+
536
+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server).
537
+
538
+
- Open your app that you created in [Create a Function App](#create-a-function-app) in VSCode
539
+
- Press 'F1' and search for 'Azure Functions: Create Function'
540
+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
541
+
- 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.
632
+
- Hit 'F5' to run your code. This will start up the Functions Host with a local HTTP Trigger and SQL Input Binding.
633
+
- Click the link that appears in your terminal.
634
+
- You should see your database output in the browser window.
635
+
- 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!
636
+
637
+
#### Output Binding Tutorial
638
+
639
+
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).
640
+
641
+
- Open your app in VSCode
642
+
- Press 'F1' and search for 'Azure Functions: Create Function'
643
+
- Choose HttpTrigger -> (Provide a package name) -> (Provide a function name) -> anonymous
644
+
- In the file that opens, replace the `public HttpResponseMessage run` block with the below code.
645
+
646
+
```java
647
+
public HttpResponseMessage run(
648
+
@HttpTrigger(
649
+
name = "req",
650
+
methods = {HttpMethod.GET},
651
+
authLevel = AuthorizationLevel.ANONYMOUS,
652
+
route = "addemployees-array")
653
+
HttpRequestMessage<Optional<String>> request,
654
+
@SQLOutput(
655
+
commandText = "dbo.Employees",
656
+
connectionStringSetting = "SqlConnectionString")
657
+
OutputBinding<Employee[]> output) {
658
+
659
+
output = new Employee[]
660
+
{
661
+
new Employee(1, "Hello", "World", "Microsoft", "Functions"),
662
+
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*
670
+
671
+
- 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.
672
+
- 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!
0 commit comments