Web 2.0 application allows users to enter SQL into a text box and submit it to a SQL Server backend. One of our users reported a failure submitting a simple query. It turns out the problem is that there is a newline character proceeding the from clause, when this is removed the error does not occur. The call throwing the exception is getParameterMetaData().
Using Cut N Paste from a UNIX envrionment the end of line (EOL) is a newline (\n). The parser does not seem to recognize these as a delimiter and failes to parse the query properly.
Execute the attached program using the following command - the logon specified must be able to create and delete tables in the database.
You supply the connection URL for the SqlServer you will be using to run the test. The required tables are created, populated with data and then deleted. The output from the program is below. I have annotated the output in this font:
java ParamMetaDataProblem "jdbc:sqlserver://<serverHost>:<port>;databaseName=<DBname>;user=<username>;password=<password>"
* java -cp .\sqljdbc4.jar;.;%CLASSPATH% ParamMetaDataProblem "jdbc:sqlserver://sqlHost:1433;databaseName=dbname;user=adm;password=xxx"