1

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

テーブル名をハードコーディングすると、適切な結果が得られます。親切に助けてください。ありがとう

4

1 に答える 1

2

@UseStringTemplate3StatementLocator で注釈を付ける必要があります。それはすでにここで議論されました。

于 2016-01-08T06:47:24.687 に答える