Link to home
Start Free TrialLog in
Avatar of jlguerra
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(strQuery);
// ***** 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/datosbasicosidentificacion_agregar.jsp');"/>

// ********** ENVIAR CODE ************
function enviar(acc) {
      document.frmForm.action=acc;
      document.frmForm.method="post";
      document.frmForm.submit();
}

// ****** JSP PAGE WRITING ON DB CODE ********
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());    
   
Connection conex = DriverManager.getConnection("jdbc:oracle:thin:@XX.XX.X.X:1521:SNIPDESA", "USER", "PWD");
   
conex.setAutoCommit(false);    

try{
      Statement stmt = conex.createStatement();          
      intResultado = stmt.executeUpdate(strQuery);  
    }catch(SQLException se){
      // ************** ERROR *****************
    }

    if(intResultado==-1){
      conex.rollback();
      blnResultado = false;
    }else{
      conex.commit();
    }    
    conex.close();
    response.sendRedirect("../pages/blank.html");


Please help me is urgent,   Thanks a lot.
Avatar of jlguerra
jlguerra

ASKER

if i put the code on other JSP page no problem, the problem is present when i call to the JAVA function:             Acceso.insertar(strSQL);

public static boolean insertarAccesoDB(String strSQL) throws java.lang.Exception
   {
    int intResultado=-1;
    boolean blnResultado=true;

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());    

Connection conex = DriverManager.getConnection("jdbc:oracle:thin:@XX.XX.X.X:1521:SNIPDESA", "USER", "PWD");

    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;
   }
   
How is it working?
>>><input type="submit" value="Grabar" name="cmdGrabar" onclick="javascript:enviar(document.forms[0],'../scripts/datosbasicosidentificacion_agregar.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.

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.
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
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial