posted 18 years ago
try {
if (supportAutoGeneratedKeys) {
p = JForumExecutionContext.getConnection().prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS);
} else {
p = JForumExecutionContext.getConnection().prepareStatement(sql);
}
p.setInt(1, id);
p.setString(2, role.getName());
// there no the third parameter values!!!
p.executeUpdate();
if (roleValues != null) {
int roleId = -1;
if (supportAutoGeneratedKeys) {
rs = p.getGeneratedKeys();
rs.next();
roleId = rs.getInt(1);
} else {
p = JForumExecutionContext.getConnection().prepareStatement(
autoKeysQuery);
rs = p.executeQuery();
if (rs.next()) {
roleId = rs.getInt(1);
}
}
rs.close();
rs = null;
p.close();
p = null;
if (roleId == -1) {
throw new SQLException("Could not obtain the latest role id");
}
p = JForumExecutionContext.getConnection().prepareStatement(
SystemGlobals.getSql("PermissionControl.addRoleValues"));
for (Iterator iter = roleValues.iterator(); iter.hasNext(); ) {
RoleValue rv = (RoleValue) iter.next();
p.setInt(1, roleId);
p.setString(2, rv.getValue());
p.executeUpdate(); // when debug here throw err !!
}
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
the sql have three parameter but before p.executeUpdate(); only set two parameter
:
INSERT INTO jforum_roles (role_id, group_id, name, role_type ) VALUES (jforum_roles_seq.nextval, ?, ?, ?)
p.setInt(1, id);
p.setString(2, role.getName());
[originally posted on jforum.net by jyhcyd]