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.
LVL 1
jlguerraAsked:
Who is Participating?
 
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0
 
jlguerraAuthor Commented:
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;
   }
   
0
 
kupra1Commented:
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.

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
jlguerraAuthor Commented:
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
0
 
kupra1Commented:
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.
0
 
jlguerraAuthor Commented:
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()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.