[英]How do I create a Dynamic Sql Query at runtime using JDBI's Sql Object API?
[英]Binding table names to SQL query using JDBI
我正在使用JDBI发布一个简单的mysql select查询。 在这种情况下,如果我尝试绑定表名,则会收到错误的SQL语法错误。
程式码片段:
@SqlQuery("select * from <table> where rowid=:rowid")
@SingleValueResult
@Mapper(ContentRecordMapper.class)
public abstract Optional<Document> getRecord(@Define("table") String table, @Bind("rowid") String rowid);
如果执行此,我得到
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<table> where rowid='row1'' at line 1 [statement:"select * from <table> where rowid=:rowid", located:"select * from <table> where rowid=:rowid", rewritten:"/* ContentDAO.getRecord */ select * from <table> where rowid=?", arguments:{ positional:{}, named:{rowid:'row1'}, finder:[]}]
如果我对表名进行硬编码,则将得到正确的结果。 请帮助。 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.