Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLServerResultSetMetaData performs checkClosed and that's causing issues #678

Closed
phaninra opened this issue Apr 17, 2018 · 4 comments
Closed
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. Work in Progress The pull request is a work in progress
Projects

Comments

@phaninra
Copy link

Driver version or jar name

6.3.3.jre7-preview

SQL Server version

2016

Client operating system

Windows 7

Java/JVM version

"1.8.0"

Problem description

The following example can be found in the javadocs of java.sql.ResultSetMetaData

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();

I've a similar operation which uses org.springframework.jdbc.object.MappingSqlQuery<T> to execute the query and then gets hold of ResultSetMetaData object.

The call getColumnCount works fine with jTDS but not with mssql driver as SQLServerResultSetMetaData checks whether the connection is closed.

I might be missing something but could not figure it out. Thanks.

@ulvii
Copy link
Contributor

ulvii commented Apr 18, 2018

Hi @phaninra ,

Just to confirm, does the issue happen only when the result set is closed before rsmd.getColumnCount();?

So repro code would be something like this?

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
rs.close()
int numberOfColumns = rsmd.getColumnCount();

@phaninra
Copy link
Author

phaninra commented Apr 18, 2018

Yep, and I believe it's due to this - https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java#L670

I realize that it's Spring JdbcTemplate which is closing the ResultSet. However, is there any reason for checking if the connection has been closed inside SQLServerResultSetMetaData?

@ulvii
Copy link
Contributor

ulvii commented Apr 18, 2018

According to JDBC specs, ResultSetMetaData instances that were created by a ResultSet that has been closed should still be accessible. Hence this is a deficiency in the driver. We will address the issue, please stay tuned.

@ulvii ulvii added Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. Work in Progress The pull request is a work in progress labels Apr 18, 2018
@cheenamalhotra cheenamalhotra added this to In progress in MSSQL JDBC Apr 19, 2018
@ulvii
Copy link
Contributor

ulvii commented May 1, 2018

Fixed in #685

@ulvii ulvii closed this as completed May 1, 2018
MSSQL JDBC automation moved this from In progress to Closed Issues May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. Work in Progress The pull request is a work in progress
Projects
MSSQL JDBC
  
Closed Issues
Development

No branches or pull requests

2 participants