My version table has 8 attributes, all are populated when inserting a Project (One to many relationship, projects – versions). Why do I get this error if I have the complete fields? Or how are values loaded to a table (version) that depends on another (project)?
(codeProject is FK -Cascade-)
Parameter index out of range (8 > number of parameters, which is 7). Error in VersionDAO
public class VersionDAO {
ConexionSQL conectar = new ConexionSQL();
Connection con;
PreparedStatement ps;
ResultSet rs;
String changeVersion;
public int insertarVer(Version ver, Proyecto pro) {
String sql = "INSERT INTO version (idVersion, nameVersion, efficVersion, acumCases, acumFail, acumTime, contPruebas, codeProject) VALUES (?,?,?,?,?,?,?,(SELECT code FROM proyecto))";
try {
con = conectar.getConexionSQL();
ps=con.prepareStatement(sql);
ps.setInt(1, ver.getIdversion());
ps.setString(2, ver.getNameVersion());
ps.setDouble(3, 0.0);
ps.setInt(4, ver.getAcumCasos());
ps.setDouble(5, 0.0);
ps.setDouble(6, 0.0);
ps.setInt(7, ver.getContPruebas());
ps.setInt(8, pro.getCod());
ps.executeUpdate();
return 1;
} catch(Exception e){
e.printStackTrace();
}
return 0;
}
Table Project (Proyecto in spanish)
public class ProyectoDAO {
ConexionSQL conectar = new ConexionSQL();
Connection con;
PreparedStatement ps;
ResultSet rs;
public int insertar(Proyecto p) {
String sql = "INSERT INTO proyecto (code, name, status, language, duration, advance, effec) VALUES (?,?,?,?,?,?,?)";
try {
con = conectar.getConexionSQL();
ps=con.prepareStatement(sql);
ps.setInt(1, p.getCod());
ps.setString(2, "Prueba");
ps.setInt(3, p.getStatus());
ps.setString(4, "PHP");
ps.setInt(5, p.getDuracion());
ps.setInt(6, p.getAvance());
ps.setDouble(7, 0.0);
ps.executeUpdate();
return 1;
} catch(Exception e){
e.printStackTrace();
}
return 0;
}
2
Answers
I see 7 question marks in your upper SQL statement but 8 calls of ps.setXXXX().
for the first code, instead you should get the code of the project out of the request.