【发布时间】:2018-04-10 15:11:59
【问题描述】:
private static final String QUERY = "SELECT * FROM " + TABLE_SONG_DETAILS + " WHERE " + TABLE_SONG_DETAILS + "." + "artist" + "=? ORDER BY track ?";
private PreparedStatement queryAllSongsInfo = conn.prepareStatement(QUERY);
// the user inputs the artist_name and ORDER
queryAllSongsInfo.setString(1, artist_name);
if (order == ORDER_BY_DESC) {
queryAllSongsInfo.setString(2, "DESC");
} else {
queryAllSongsInfo.setString(2, "ASC");
}
显示错误:SQL 错误或缺少数据库(near “?”: syntax error)
如果我只包含第一个占位符,那么它工作正常。
queryAllSongsInfo.setString(1, artist_name);
为什么我不能使用多个占位符??为什么第二个占位符不考虑用户的第二个输入?
【问题讨论】:
标签: java jdbc sqlite prepared-statement placeholder