i have strange problem. i'm executing insert using prepared statement this:
try (connection connection = connectionpool.getconnection(); preparedstatement ps = connection.preparestatement(sql, statement.return_generated_keys)) { //todo: caching of ps int = 1; parametermetadata pmd = ps.getparametermetadata(); ... } catch (sqlexception e) { throw new tgfioexception("error executing sql command " + sql, e); }
insert statement this:
insert dbo.currencyrates(ratedate, currencyid, rate) values ( ?, ?, ? )
unfortunately fails following exception:
com.microsoft.sqlserver.jdbc.sqlserverexception: com.microsoft.sqlserver.jdbc.sqlserverexception: incorrect syntax near keyword 'where'. @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:190) @ com.microsoft.sqlserver.jdbc.sqlserverparametermetadata.<init>(sqlserverparametermetadata.java:426) @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement.getparametermetadata(sqlserverpreparedstatement.java:1532) @ com.jolbox.bonecp.preparedstatementhandle.getparametermetadata(preparedstatementhandle.java:246)
there no in statement, puzzled why fails on metadata extraction...
edit:
sql server = 10.50.2500.0 express edition, driver = sqljdbc4.jar 4.0 package
also, using getparametermetadata because need set params null , preferred method use setnull() need sqltype.
edit2: i've tested driver sqljdbc41 newest 6.0 package - results same
edit3: i've removed call getparametermetadata() , worked, unfortunately generic part should max portable, yet not work single table (inserts other tables on same database works fine !!!)
edit4: i've tried different insert statements table , of them works fine if skip ps.getparametermetadata()
, fail when call it. if try 2 or more params usual near where
error. if try 1 column insert error stating column name incorrect, if correct , without meta data call works fine. try trace driver tries underneath...
after tracing on driver (many a_horse_with_no_name), i've come funny conclusion.
the solution question to:
replace following insert statement
insert currencyrates(ratedate, currencyid, rate) values ( ?, ?, ? )
with statement
insert currencyrates (ratedate, currencyid, rate) values ( ?, ?, ? )
logic behind sql driver metadata extraction in background, , creates query following fragment: ... currencyrates(ratedate ...
if not put space after table name, yet ordinary call possible!
edit: inconsistency (putting aside valid insert) should consistently accept or reject query no matter if call meta data or not.
Comments
Post a Comment