in Education by
I have a strange problem. I'm executing insert using prepared statement like this: try (Connection connection = connectionPool.getConnection(); PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { //TODO: caching of PS int i = 1; ParameterMetaData pmd = ps.getParameterMetaData(); ... } catch (SQLException e) { throw new TGFIOException("Error executing SQL command " + sql, e); } Insert statement is like this: insert into dbo.CurrencyRates(RateDate, CurrencyID, Rate) values ( ?, ?, ? ) Unfortunately it fails with following exception: com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'WHERE'. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.(SQLServerParameterMetaData.java:426) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:1532) at com.jolbox.bonecp.PreparedStatementHandle.getParameterMetaData(PreparedStatementHandle.java:246) There is no WHERE in the statement, so I am puzzled why it fails on metadata extraction... EDIT: SQL Server = 10.50.2500.0 Express Edition, Driver = sqljdbc4.jar from 4.0 package Also, I am using getParameterMetaData because I need to set some params to null and the preferred method is to use setNull() where you need SQLType. EDIT2: I've tested with Driver sqljdbc41 from newest 6.0 package - results are the same EDIT3: I've removed call to getParameterMetaData() and it worked, unfortunately it is a generic part that should max portable, yet it does not work with this single table (inserts to other tables on the same database works fine !!!) EDIT4: I've tried with different insert statements for this table and all of them works fine if I skip ps.getParameterMetaData() and fail when I call it. If I try with 2 or more params I get usual near WHERE error. If I try one column insert I get an error stating that the column name is incorrect, even if it is correct and without the meta data call it works perfectly fine. I will try to trace what driver tries to do underneath... JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
After some tracing on what actually the driver does (many thanks a_horse_with_no_name), I've come to some funny conclusion. The solution for my question is to: Replace following insert statement INSERT INTO CurrencyRates(RateDate, CurrencyID, Rate) VALUES ( ?, ?, ? ) With this statement INSERT INTO CurrencyRates (RateDate, CurrencyID, Rate) VALUES ( ?, ?, ? ) Logic behind that is that SQL driver does some metadata extraction in the background, and it creates a query with following fragment: ... FROM CurrencyRates(RateDate WHERE ... if you do not put space after table name, yet for the ordinary call this is perfectly possible! EDIT: This is obviously an inconsistency as (putting aside what actually is a valid insert) it should consistently accept or reject this query no matter if I call for meta data or not.

Related questions

0 votes
    I am using spring-boot latest 2.1.3 release and want to start with testcases, but this is not ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am using spring-boot latest 2.1.3 release and want to start with testcases, but this is not ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I have a scenario where my hypothesis fits my training set well but fails to generalize for the test set. What ... (2)Overfitting (3)Generalization Failure (4)None of the options...
asked May 20, 2021 in Technology by JackTerrance
0 votes
    I have an old server with a defunct evaluation version of SQL 2000 on it (from 2006), and two ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have an old server with a defunct evaluation version of SQL 2000 on it (from 2006), and two ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am using EF for access MS SQL data with help LINQ. How can I get current isolation level ? For ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    We have a customer requesting data in XML format. Normally this is not required as we usually just hand ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    We have a customer requesting data in XML format. Normally this is not required as we usually just hand ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    What are Tables and Fields in MSSQL?...
asked Dec 8, 2020 in Technology by JackTerrance
0 votes
    Is it possible to setup a JDBC connection to Oracle without providing username/password information in a ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Is it possible to setup a JDBC connection to Oracle without providing username/password information in a ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Is it possible to setup a JDBC connection to Oracle without providing username/password information in a ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Where is the error icon shown in the Internet Explorer? (a) Taskbar (b) Status bar (c) Both ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    Where is the error icon option available? (a) Tools (b) Help (c) File (d) Edit This question ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    When I plot densities with ggplot, it seems to be very wrong around the limits. I see that geom_density ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
...