我在我的托管bean中进行查询。这是代码: try { PreparedStatement checkDB = (PreparedStatement) con.prepareStatement("SELECT * FROM boats where age= ? and color <> ?"); checkDB.setString(1, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("age")); checkDB.setString(1, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("color")); ResultSet res=(ResultSet) checkDB.executeQuery(); return res; } catch (Exception e) { return null; }我确信此查询可以在不使用“ color ?”条件的情况下工作。但是当我添加时这是行不通的。我认为我的运营商不平等存在问题。我搜索了它的用法,并看到了与我相同的用法。我也尝试过“!=”,但也没有用。我正在使用MySQL数据库。有人可以帮忙吗?谢谢 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 它不起作用,因为您使用了错误的参数索引。它应该是: checkDB.setString(1, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("age")); checkDB.setString(2, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("color")); (adsbygoogle = window.adsbygoogle || []).push({});
07-26 00:57