我正在使用 JDBI 发出一个简单的 mysql 选择查询。如果我尝试绑定表名,我会收到错误的 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:[]}]
如果我对表名进行硬编码,我会得到正确的结果。请帮忙。谢谢