question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors in getParameterMetaData() when non-space characters in query

See original GitHub issue

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 8103dc386f1210f93216c8a37fa4e018f98bdf38) 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 8103dc386f1210f93216c8a37fa4e018f98bdf38 (for JDK8) against Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
xiangyushawncommented, Jun 21, 2017

Hello @chadberchek , I created a PR #351 to fix the issues you found.

Thank you very much for providing the test code, it really helped a lot! Would you mind if I add your test code to the PR as one of the unit tests?

1reaction
vobariancommented, Jun 19, 2017

@ajlam I ran these tests with 4.0.2206.100 (from Maven, ‘com.microsoft.sqlserver:sqljdbc4:4.0.2206.100’) and got the same results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - PreparedStatement.getParameterMetaData() throws ...
PreparedStatement.getParameterMetaData() throws ArrayIndexOutOfBoundsException when having comment and parameter within sql-string [closed].
Read more >
prevent interpretation of special characters in enter-query mode
This only happens if < is the first non-space character in the search string. Does anyone know of a way to prevent oracle...
Read more >
Strange Behavior with Whitespace String - Vertica Forum
What about the fact that a string consisting only of spaces is 'trimmed' while a string of non-space characters raises an error.
Read more >
[^] (Wildcard - Character(s) Not to Match) (Transact-SQL)
Matches any single character that is not within the range or set specified between the square brackets [^] . These wildcard characters can ......
Read more >
Control character in XML output - Sybase Infocenter
Error constant, SQLE_CONTROL_CHARACTER_IN_XML_OUTPUT ... A non-space character less than hex 20 was encountered while generating XML content.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found