JDBC中:设置从1开始
例:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/...","root","123");
String sql = "insert into t_user values (?,?,?)";
PreparedStatment ps = con.prepared(sql);
ps.setString(1,"...");
ps.setString(2,"...");
ps.setString(3,"...");
Hibernate中:设置从0开始
例:
String hql = "from User user where user.id=? and user.username=? ";
Query q = sessionFactory.getCurrentSession.createQuery(hql);
q.setParameter(0,"...");
q.setParameter(1,"...");
PS:Hibernate推荐使用?加字符串识别的方式设置参数
例:
String hql = "from User user where user.id=?id and user.username=?username ";
Query q = sessionFactory.getCurrentSession.createQuery(hql);
q.setParameter("id","...");
q.setParameter("username","...");