I discovered a variety of scenarios where PreparedStatement.getParameterMetaData() either throws an exception or returns an incorrect parameter count in a subsequent call to getParameterCount(), all of which appear to be related to the presence or absence of whitespace characters (spaces, newlines, tabs).
Below is a test suite Gist which demonstrates some of the issues. Five of the seven tests fail for me (the other two are just to demonstrate that the errors are only due to whitespace differences). Note that each test first executes the statement to prove that the statement really works and is not the problem; only fetching the parameter metadata is the problem. Please note that most of the issues with with line breaks also occur with tabs.
https://gist.github.com/chadberchek/1d0c686890a69e171e6e01d0ec6fffdb#file-experiment-java
Here is a summary of my results:
| Test |
Result |
| insertWithLineBreakBeforeTableName (build of 8103dc3) |
SQLServerException: Incorrect syntax near the keyword 'WHERE'. |
| insertWithLineBreakBeforeTableName (6.1.0.jre8) |
SQLServerException: Unable to identify the table insert into experiment (id) values (?) for the metadata. |
| insertWithNoSpaceAfterTableName |
SQLServerException: Invalid column name 'id'. |
| updateWithLineBreakAfterWhere |
SQLServerException: Incorrect syntax near the keyword 'where'. |
| updateWithLineBreakBeforeFirstParameter |
Parameter count mismatch Expected :2 Actual :0 |
| updateWithLineBreakAfterUpdate |
SQLServerException: Unable to identify the table update experiment set id = ? where id = ? for the metadata. |
Tested with driver 6.1.0.jre8 and also a local build of 8103dc3 (for JDK8) against Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64).
I discovered a variety of scenarios where
PreparedStatement.getParameterMetaData()either throws an exception or returns an incorrect parameter count in a subsequent call togetParameterCount(), all of which appear to be related to the presence or absence of whitespace characters (spaces, newlines, tabs).Below is a test suite Gist which demonstrates some of the issues. Five of the seven tests fail for me (the other two are just to demonstrate that the errors are only due to whitespace differences). Note that each test first executes the statement to prove that the statement really works and is not the problem; only fetching the parameter metadata is the problem. Please note that most of the issues with with line breaks also occur with tabs.
https://gist.github.com/chadberchek/1d0c686890a69e171e6e01d0ec6fffdb#file-experiment-java
Here is a summary of my results:
Tested with driver 6.1.0.jre8 and also a local build of 8103dc3 (for JDK8) against Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64).