jdbc - java program not getting inside while loop for unique row result set -
i have result set should contain 1 row (i have tested this). program not getting inside while(rs2.next()) loop, have noticed after debugging. that's why i'm getting sqlexception : not variables bound.
resultset constitues = cnx.createstatement().executequery(request.getconstitues()); while(constitues.next()){ preparedstatement ps = cnx.preparestatement(request.setnewconstitue()); preparedstatement ps2 = cnx.preparestatement(request.getdossierfromnumeroparcelle()); ps2.setint(1, constitues.getint("num_ordre")); ps2.setint(2, constitues.getint("num_parcelle")); //rs2 contains 1 row resultset rs2 = ps2.executequery(); // program not entering loop while(rs2.next()){ ps.setint(1, rs2.getint("num_dossier")); ps.setstring(2, rs2.getstring("indice")); ps.setstring(3, constitues.getstring("observations")); ps.setint(4, constitues.getint("type_consistance")); } ps.executeupdate(); rs2.close(); ps.close(); } request.getconstitues() :
select * parc_constitues request.setnewconstitue() :
insert constitue(num_dossier,indice,observation,code_consistance) values(?,?,?,?) request.getdossierfromnumeroparcelle() :
select num_dossier,indice parc_parcelles num_ordre = ? , num_parcelle= ? why program not getting inside while loop ?
i suspect data not available in db or failing retrieve db.
but way check condition before go while loop
boolean isempty = ! rs.first(); and print isempty debugging.
so use
if(!isempty) { while(rs2.next()){ ps.setint(1, rs2.getint("num_dossier")); ps.setstring(2, rs2.getstring("indice")); ps.setstring(3, constitues.getstring("observations")); ps.setint(4, constitues.getint("type_consistance")); } }
Comments
Post a Comment