Ad

Declare Output Parameter And Select It Like A Result Of Query, T-SQL, JAVA

- 1 answer

I have a sql query:

DECLARE @output varchar(100) exec map.GetGenreStatusName 'Genre', '2018-03-16', @output OUTPUT select @output;

It returns smth like:

<anonymous>
 Completed

I need take it from java code. My variant is:

final String statusCheck = "DECLARE @output varchar(100) exec map.GetGenreProtocolStatusName ?, ?, ? OUTPUT select @output;";
List<String> chekList = new ArrayList<>();
 try (CallableStatement statement = connection.prepareCall(statusCheck)) {
       statement.setString(1, packageName);
        statement.setDate(2, date);
        statement.registerOutParameter("output", 12);
        statement.execute();
        ResultSet checkStatusResult = (ResultSet) statement.getObject(0);
        chekList.add(checkStatusResult.getString(0));
    }

How do I take this string "Completed" from select to my list? I tried different variant with "?" setting and registering in/out parameters, I tried execute it like a query, but nothing.

Ad

Answer

Have changed a string to:

final String statusCheck = "exec map.GetGenreProtocolStatusName ?, ?, ?;"; 

Code to:

final Connection connection = DriverManager.getConnection(dataSourceUrl, dbProperties);

    List<TvScheduleInterval> scheduleIntervals = new ArrayList<>();
    List<String> checkList = new ArrayList<>();

    try (CallableStatement statement = connection.prepareCall(statusCheck)) {
        statement.setString(1, packageName);
        statement.setDate(2, date);
        statement.registerOutParameter(3,12);
        statement.execute();
        checkList.add(statement.getString(3));
    }

Working now.

Ad
source: stackoverflow.com
Ad