Я пытаюсь написать функцию, которая запускается служебной шиной и записать код в Azure. Я здесь застрял не в состоянии получить доступ к БД вообще. Я не получаю никакой ошибки здесь, но я также не получаю Печать результатов из оператора выбора (Test2).
Что не так в коде?
Перед запуском этого кода я скачал драйвер jdb c и последовал следующему примеру. http://biercoff.com/add-microsoft-sql-jdbc-driver-to-maven/
package com.function;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
/**
* Azure Functions with Azure Storage Queue trigger.
*/
public class TopicTriggerSQLOutput {
/**
* This function will be invoked when a new message is received at the specified path. The
message contents are provided as input to this function.
*/
@FunctionName("TopicTriggerSQLOutput")
public void run(
@ServiceBusTopicTrigger(
name = "message",
topicName = "newtopic",
subscriptionName = "newsubscription",
connection = "topicconnstring"
) String message,
final ExecutionContext context
) {
/*Creating SQL Connection. I need help here:
*/
String connectionUrl =
"jdbc:sqlserver://sql...;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
ResultSet resultSet = null;
try (Connection connection = DriverManager.getConnection(connectionUrl);
Statement statement = connection.createStatement();) {
context.getLogger().info("Test 1"); // This is printed out.
// Create and execute a SELECT SQL statement.
String selectSql = "SELECT TOP 10 artist FROM [dbo].[RadioEventsTarget]";
resultSet = statement.executeQuery(selectSql);
// Print results from select statement
while (resultSet.next()) {
System.out.println(resultSet.getString(2) + " " + resultSet.getString(3));
context.getLogger().info("Test 2"); // This is never printed.
}
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
context.getLogger().info("Message: " + message); // this is printed.
}
}