jlguerra
asked on
Duplicate Register on Database with JSP - ORACLE
Hi friends,
i have an application JSP, and i need write a regsiter on the Database but wen i Insert, the page insert two times. The problem is i have a JSP+HTML page and that call other JSP page when this page do response.sendredirect();
// ***** the cursor execute again the Insert
intResultado = stmt.executeUpdate(strQuer y);
// ***** the cursor execute again the Insert
the code is like this:
// ********** INITIAL PAGE CODE ************
<input type="submit" value="Grabar" name="cmdGrabar" onclick="javascript:enviar (document. forms[0],' ../scripts /datosbasi cosidentif icacion_ag regar.jsp' );"/>
// ********** ENVIAR CODE ************
function enviar(acc) {
document.frmForm.action=ac c;
document.frmForm.method="p ost";
document.frmForm.submit();
}
// ****** JSP PAGE WRITING ON DB CODE ********
DriverManager.registerDriv er(new oracle.jdbc.driver.OracleD river());
Connection conex = DriverManager.getConnectio n("jdbc:or acle:thin: @XX.XX.X.X :1521:SNIP DESA", "USER", "PWD");
conex.setAutoCommit(false) ;
try{
Statement stmt = conex.createStatement();
intResultado = stmt.executeUpdate(strQuer y);
}catch(SQLException se){
// ************** ERROR *****************
}
if(intResultado==-1){
conex.rollback();
blnResultado = false;
}else{
conex.commit();
}
conex.close();
response.sendRedirect("../ pages/blan k.html");
Please help me is urgent, Thanks a lot.
i have an application JSP, and i need write a regsiter on the Database but wen i Insert, the page insert two times. The problem is i have a JSP+HTML page and that call other JSP page when this page do response.sendredirect();
// ***** the cursor execute again the Insert
intResultado = stmt.executeUpdate(strQuer
// ***** the cursor execute again the Insert
the code is like this:
// ********** INITIAL PAGE CODE ************
<input type="submit" value="Grabar" name="cmdGrabar" onclick="javascript:enviar
// ********** ENVIAR CODE ************
function enviar(acc) {
document.frmForm.action=ac
document.frmForm.method="p
document.frmForm.submit();
}
// ****** JSP PAGE WRITING ON DB CODE ********
DriverManager.registerDriv
Connection conex = DriverManager.getConnectio
conex.setAutoCommit(false)
try{
Statement stmt = conex.createStatement();
intResultado = stmt.executeUpdate(strQuer
}catch(SQLException se){
// ************** ERROR *****************
}
if(intResultado==-1){
conex.rollback();
blnResultado = false;
}else{
conex.commit();
}
conex.close();
response.sendRedirect("../
Please help me is urgent, Thanks a lot.
How is it working?
>>><input type="submit" value="Grabar" name="cmdGrabar" onclick="javascript:enviar (document. forms[0],' ../scripts /datosbasi cosidentif icacion_ag regar.jsp' );"/>
// ********** ENVIAR CODE ************
function enviar(acc) {
The call to enviar has two arguments in it whereas the method declaration contains only one parameter.
Further, check whether this function is getting called twice.
Also, paste your query.
>>><input type="submit" value="Grabar" name="cmdGrabar" onclick="javascript:enviar
// ********** ENVIAR CODE ************
function enviar(acc) {
The call to enviar has two arguments in it whereas the method declaration contains only one parameter.
Further, check whether this function is getting called twice.
Also, paste your query.
ASKER
sorry, i paste de error call. the call is a SummitValidate(form,pageTo ) and that javascript validate the form elements and later do it a summit to the pageTo, but the problem is basicaly the instance two times the function Acceso.insertar(strSQL); if i do a other page and the page with the forms element call a second page, where i construct the SQL and set a session variable sentence and later this page call other JSP page what only have the executeupdate sentence, that function correctly. maybe the problem is the instance a function Acceso.InsertarDB(), i dont´ now. but mean i dont´ the solution i do it like i write here, call a page later other page and later other. maybe if you like i send the complete code. thanks for your time and dedication on the matter, perhaps if you execute the code to see what happens so that he is well strange since. If i paste the code in a single project this part and although I call to the function a single time this is executed twice times the executeupdate
jlguerra,
it's not a problem at all. it will be easier for me to look at if I have the code in front of me.
it's not a problem at all. it will be easier for me to look at if I have the code in front of me.
ASKER
I do an other page and the problem finish. then the solution is make three page 1) accept the user inputs, 2) make the SQL sentences, 3) execute the stmt.executeupdate()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
public static boolean insertarAccesoDB(String strSQL) throws java.lang.Exception
{
int intResultado=-1;
boolean blnResultado=true;
DriverManager.registerDriv
Connection conex = DriverManager.getConnectio
conex.setAutoCommit(false)
Statement stmt = conex.createStatement();
intResultado = stmt.executeUpdate(strSQL)
if(intResultado==-1){
conex.rollback();
blnResultado = false;
}else{
conex.commit();
}
conex.close();
return blnResultado;
}