2017-09-20 4 views
0

用意された文を使用してxmlexists関数の文字列パラメータを注入しようとするとエラーが発生します。Derby PreparedStatementはXMLEXISTS関数内にパラメータを挿入しません

Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); 
Connection con = DriverManager.getConnection("jdbc:derby:c:\\mydb"); 
PreparedStatement st = con.prepareStatement("select * from \"Data\" where xmlexists(? passing by ref \"data\")"); 
st.setString(1, "//*[text()[contains(., 'v1')]]"); 
ResultSet rs = st.executeQuery(); 

エラー:それはプリペアドステートメントずに手動で組み込まれているとき

ERROR 42Z75: XML query expression must be a string literal.

文は成功します。

select * 
from "Data" 
where xmlexists('//*[text()[contains(., ''v1'')]]' passing by ref "data") 

どのような理由が考えられますか?

答えて

1

引用から:https://db.apache.org/derby/docs/10.13/ref/rreffuncxmlexists.html

構文:ダービーそれは興味深いエンハンスメントあろうxmlexists機能 https://db.apache.org/derby/docs/10.13/ref/rrefsqlj1083019.html

+0

内部動的パラメータを許可しないよう XMLEXISTS (xqueryStringLiteral PASSING BY REF xmlValueExpression [ BY REF ])

xqueryStringLiteral
Must be specified as a string literal. If this argument is specified as a parameter, an expression that is not a literal, or a literal that is not a string (for example an integer), Derby throws an error. The xqueryStringLiteral argument must also be an XPath expression. Derby does not support full XQuery, only the XPath subset. If it cannot compile or execute the query argument, Derby throws an SQLException.

サウンド。 Derbyはオープンソースです:おそらくあなたはそのような機能を提供することができます! –

関連する問題