JDBC里面的占位符举例:
String sql = "select sex,mathGrade from t_user where userName=? and age=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1,"小明"); ps.setIng(2,17);
注意:此时的索引是从1开始的整数!
/*****************************************************/
Hibernate的占位符举例:
String hql="FROM Book b WHERE b.bookName=?"; Query query=getSession().createQuery(hql).setString(0, bookName); Book book=(Book) query.uniqueResult();