• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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.
0
jlguerra
Asked:
jlguerra
  • 3
  • 2
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now