Skip to content

Executing a PreparedStatement with SET SHOWPLAN_ALL ON or SET SHOWPLAN_XML ON does not return a ResultSet. #778

@rtwruck

Description

@rtwruck

Driver version or jar name

mssql-jdbc-7.0.0.jre8.jar

SQL Server version

12.00.5571

Client operating system

Linux

Java/JVM version

Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Table schema

any

Problem description

Executing a PreparedStatement with SET SHOWPLAN_ALL ON or SET SHOWPLAN_XML ON does not return a ResultSet.
It makes no difference whether prepareStatement is called before or after issuing the SET statement.
A ResultSet with the expected plan is returned when using createStatement().execute(sqlText) - but that obviously does not work when the statement takes parameters.
In addition, there's a NullPointerException when you call PreparedStatement.getParameterMetaData() with SET SHOWPLAN in effect, presumably because the returned ResultSet contains the plan:
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.parseQueryMeta(SQLServerParameterMetaData.java:211)
at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.(SQLServerParameterMetaData.java:602)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3057)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:3068)

Expected behavior and actual behavior

Expected:
connection.createStatement().execute("SET SHOWPLAN_ALL ON") == false &&
connection.prepareStatement(sqlText).execute() == true
Actual:
connection.createStatement().execute("SET SHOWPLAN_ALL ON") == false &&
connection.prepareStatement(sqlText).execute() == false

Repro code

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions