繁体   English   中英

使用JDBI将表名称绑定到SQL查询

[英]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:[]}]

如果我对表名进行硬编码,则将得到正确的结果。 请帮助。 谢谢

您应该使用@ UseStringTemplate3StatementLocator进行注释。 这里已经讨论过

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM