Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:01:49+00:00 2026-06-17T12:01:49+00:00

When I try to run a code I have this mistake: java.lang.Exception: Lock wait

  • 0

When I try to run a code I have this mistake: java.lang.Exception: Lock wait timeout exceeded; try restarting transaction. I have see the inoodb status and I get this. How can I translate this into a language which I know?. How can I modify the time for the innodb variable?.

Thanks

mysql> show engine innodb status\g

| InnoDB |      |
=====================================
130117 13:25:22 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 19 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 5, signal count 5
Mutex spin waits 0, rounds 40, OS waits 2
RW-shared spins 6, OS waits 3; RW-excl spins 0, OS waits 0
------------
TRANSACTIONS
------------
Trx id counter 0 46088
Purge done for trx's n:o < 0 45663 undo n:o < 0 0
History list length 5
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, process no 20582, OS thread id 139811275994880
MySQL thread id 39, query id 169 localhost root
show engine innodb status
---TRANSACTION 0 46087, ACTIVE 8 sec, process no 20582, OS thread id 139811275593472 inserting
mysql tables in use 1, locked 1
LOCK WAIT 5 lock struct(s), heap size 1216, 3 row lock(s), undo log entries 1
MySQL thread id 44, query id 168 172.17.150.33 root update
INSERT INTO albaranes    (id_cuenta_emisora,id_cuenta_receptora,id_pedido,id_formato_documento,descuento,nombre_report,destino_report) VALUES (    19 ,                           23 ,                         1 ,                                   2 ,                        0.0,                                null,null   )
------- TRX HAS BEEN WAITING 8 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 228 n bits 256 index `PRIMARY` of table `cluw`.`pedidos` trx id  0 46087 lock mode S locks rec but not gap waiting
Record lock, heap no 106 PHYSICAL RECORD: n_fields 13; compact format; info bits 0
0: len 4; hex 00000001; asc     ;; 1: len 6; hex 00000000b403; asc       ;; 2: len 7; hex    800000002d0110; asc     -  ;; 3: len 4; hex 00000001; asc     ;; 4: len 4; hex 00000017; asc     ;;   5: len 10; hex 32303132303430303031; asc 2012040001;; 6: len 8; hex 8000124ca5887d00; asc    L  } ;; 7: len 1; hex 80; asc  ;; 8: len 4; hex 00000000; asc     ;; 9: SQL NULL; 10: SQL NULL; 11: SQL NULL; 12: len 4; hex 00000000; asc     ;;

------------------
---TRANSACTION 0 46083, ACTIVE 9 sec, process no 20582, OS thread id 139811275794176
11 lock struct(s), heap size 1216, 9 row lock(s), undo log entries 7
MySQL thread id 43, query id 157 172.17.150.33 root
Trx read view will not see trx with id >= 0 46084, sees < 0 46084
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
73 OS file reads, 9 OS file writes, 9 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.11 writes/s, 0.11 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 17393, node heap has 1 buffer(s)
0.00 hash searches/s, 2.53 non-hash searches/s
---
LOG
---
Log sequence number 0 10153404
Log flushed up to   0 10153404
Last checkpoint at  0 10151824
0 pending log writes, 0 pending chkp writes
12 log i/o's done, 0.11 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 20742848; in additional pool allocated 1048576
Dictionary memory allocated 188160
Buffer pool size   512
Free buffers       424
Database pages     87
Modified db pages  14
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 87, created 0, written 1
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
2 read views open inside InnoDB
Main thread process no. 20582, id 139811124684544, state: sleeping
Number of rows inserted 7, updated 0, deleted 0, read 70
0.37 inserts/s, 0.00 updates/s, 0.00 deletes/s, 2.89 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

1 row in set (0.00 sec)

And this is the code which give me problems:

public TDatosRetorno sincronizarPedidos(Tdatospedidos pedido,int metodo_facturacion,int proveedor){
        TDatosRetorno resultado = new TDatosRetorno();


        System.out.println("Voy a sincronizar los pedidos ahora mismo");
        //System.out.println("Pedidos"+pedidos);
        System.out.println(pedido.getId_cuenta()+" y pedido es:"+pedido.getId_pedido());
        try {
        this.conexion = conectar();
        this.conexion.setAutoCommit(false);

        int estado_pedido=0;
        Date f_aprobacion=null;
        boolean pedido_provisionado = true;

        Date f_provision=null;
        String unidad_duracion_contrato=" ";
        int duracion_contrato=0;
        Date f_inicio_contrato = new Date();
        Date f_fin_contrato = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();

        //int id_cuenta=buscar_cuentaPedidos_ccis(pedido.getId_cuenta(),proveedor);
        //System.out.println("id_cuenta es:"+id_cuenta);
        SQL="INSERT pedidos (id_pedido,id_estado_pedido,id_cuenta,n_pedido,f_creacion,es_actualizacion,id_pedido_actualizado,f_inicio_contrato,f_fin_contrato,f_aprobacion,estado_envio)"+
        " VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        System.out.println("LA SQL de insertar pedidos es:"+SQL);
        //int key=0;
        this.pstm = this.conexion.prepareStatement(SQL,PreparedStatement.RETURN_GENERATED_KEYS);
        this.pstm.setInt(1, pedido.getId_pedido());
        this.pstm.setInt(2, 1);
        this.pstm.setInt(3, pedido.getId_cuenta());
        this.pstm.setString(4, pedido.getN_pedido());
        Object objPed = pedido.getF_creacion();
        if(objPed!=null){
            System.out.println("Fecha de creación es diferente de nulo");
            java.sql.Date f_creacionAux = new java.sql.Date(pedido.getF_creacion().getTime());  
            this.pstm.setDate(5, f_creacionAux);
        }else{
            System.out.println("Fecha de creación es nulo");
            this.pstm.setDate(5, null);
        }

        this.pstm.setBoolean(6, pedido.isEs_actualizacion());
        this.pstm.setInt(7, pedido.getId_pedido_actualizado());
        this.pstm.setDate(8, null);
        this.pstm.setDate(9, null);
        this.pstm.setDate(10, null);

        this.pstm.setInt(11, 0);




        System.out.println("Vamos a hacer la insercción de pedidos");
         int ejecutado =  this.pstm.executeUpdate();
            if(ejecutado==0){   
               System.out.println("Ejecutado tiene valor 0");
                throw new Exception("Error al grabar Pedidos");

         }

        ResultSet rs = this.pstm.getGeneratedKeys(); 
        int key = 0;
        if (rs != null && rs.next()) { 
            key = rs.getInt(1);

        }   
         System.out.println("El pedido tiene una key de:"+key);     
        System.out.println("Estamos fuera de pedidos ya");
        if(pedido.getDatos_SV()!=null){



            for (int i=0;i<pedido.getDatos_SV().length;i++){
                servID=new int[pedido.getDatos_SV().length];
                SQL="INSERT INTO servidores_virtuales (id_servidor_virtual,id_pedido,nombre_servidor,duracion_contrato,cpu_cant,ram_cant,hdd_cant,hdd_unidad,sv_pvp,cpu_pvp,ram_pvp,hdd_pvp,sv_pvp_dist,cpu_pvp_dist,ram_pvp_dist,hdd_pvp_dist,ip_pvp,ip_pvp_dist,ip_polled_pvp,ip_polled_pvp_dist,ip_custom_pvp,ip_custom_pvp_dist,data_center,cluster,plantilla,estado_aprobacion,f_aprobacion,f_provision,es_actualizacion,f_actualizacion,disco_almacenamiento) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
                System.out.println("LA SQL A METER ES:"+SQL);
                System.out.println("El número de servidores a meter es:"+pedido.getDatos_SV().length);


                PreparedStatement pstmSv = this.conexion.prepareStatement(SQL,PreparedStatement.RETURN_GENERATED_KEYS);
                //System.out.println("El virtual server id que voy a meter tiene id de ccis:"+pedido.getDatos_SV()[i].getId_servidor_virtual_ccis());

                pstmSv.setInt(1, pedido.getDatos_SV()[i].getId_servidor_virtual());
                pstmSv.setInt(2, pedido.getId_pedido()); //Last insert id de pedido

                System.out.println("Nombre del servidor:"+pedido.getDatos_SV()[i].getNombre_servidor());
                pstmSv.setString(3, pedido.getDatos_SV()[i].getNombre_servidor());
                pstmSv.setString(4, pedido.getDatos_SV()[i].getDuracion_contrato());
                pstmSv.setInt(5, pedido.getDatos_SV()[i].getCpu_cant());
                pstmSv.setString(6, pedido.getDatos_SV()[i].getRam_cant());
                pstmSv.setString(7, pedido.getDatos_SV()[i].getHdd_cant());
                pstmSv.setString(8, pedido.getDatos_SV()[i].getHdd_unidad());
                pstmSv.setDouble(9, pedido.getDatos_SV()[i].getSv_pvp());
                pstmSv.setDouble(10, pedido.getDatos_SV()[i].getCpu_pvp());
                pstmSv.setDouble(11, pedido.getDatos_SV()[i].getRam_pvp());
                pstmSv.setDouble(12, pedido.getDatos_SV()[i].getHdd_pvp());
                pstmSv.setDouble(13, pedido.getDatos_SV()[i].getSv_pvp_dist());
                pstmSv.setDouble(14, pedido.getDatos_SV()[i].getCpu_pvp_dist());
                pstmSv.setDouble(15, pedido.getDatos_SV()[i].getRam_pvp_dist());
                pstmSv.setDouble(16, pedido.getDatos_SV()[i].getHdd_pvp_dist());
                pstmSv.setDouble(17, pedido.getDatos_SV()[i].getIp_pvp());
                pstmSv.setDouble(18, pedido.getDatos_SV()[i].getIp_pvp_dist());
                pstmSv.setDouble(19, pedido.getDatos_SV()[i].getIp_polled_pvp());
                pstmSv.setDouble(20, pedido.getDatos_SV()[i].getIp_polled_pvp_dist());
                pstmSv.setDouble(21, pedido.getDatos_SV()[i].getIp_custom_pvp());
                pstmSv.setDouble(22, pedido.getDatos_SV()[i].getIp_custom_pvp_dist());
                pstmSv.setString(23, pedido.getDatos_SV()[i].getData_center());
                pstmSv.setString(24, pedido.getDatos_SV()[i].getCluster());
                pstmSv.setString(25, pedido.getDatos_SV()[i].getPlantilla());
                pstmSv.setInt(26, pedido.getDatos_SV()[i].getEstado_aprobacion());
                //Chequear nulos
                Object objAprob = pedido.getDatos_SV()[i].getF_aprobacion();
                if(objAprob!=null){


                    java.sql.Date f_aprobacionAux = new java.sql.Date(pedido.getDatos_SV()[i].getF_aprobacion().getTime());  
                    pstmSv.setDate(27, f_aprobacionAux);

                }else{
                    System.out.println("Nuloooooooooooooooooo");
                    pstmSv.setDate(27, null);
                }
                Object obj=pedido.getDatos_SV()[i].getF_provision();
                if(obj==null){
                        System.out.println("Nulooooooooooooooo");
                        pstmSv.setDate(28, null);
                }else{
                  java.sql.Date f_provisionAux = new java.sql.Date(pedido.getDatos_SV()[i].getF_provision().getTime());
                  pstmSv.setDate(28, f_provisionAux);
                }  


                pstmSv.setBoolean(29, pedido.getDatos_SV()[i].isEs_actualizacion());
                if(pedido.getDatos_SV()[i].getF_actualizacion()!=null){
                    java.sql.Date f_actualizacionAux =new java.sql.Date(pedido.getDatos_SV()[i].getF_actualizacion().getTime());
                    pstmSv.setDate(30, f_actualizacionAux);     
                }else{

                    pstmSv.setDate(30, null);

                }
                pstmSv.setString(31, pedido.getDatos_SV()[i].getDisco_almacenamiento());





                System.out.println("El estado de aprobación del pedido es:"+pedido.getDatos_SV()[i].getEstado_aprobacion());                    
                switch(pedido.getDatos_SV()[i].getEstado_aprobacion()){


                     case 0:{
                         switch(estado_pedido){
                             case 0:{
                                 estado_pedido =1;
                                 break;
                             }
                             case 1:{
                                 estado_pedido =1;
                                 break;
                             }
                             case 2:{
                                 estado_pedido = 1;
                                 break;
                             }

                         }
                         break;
                     }
                     case 1:{
                         switch(estado_pedido){

                            case 0:{
                                estado_pedido = 2;
                                break;
                            }
                            case 1:{
                                estado_pedido =1;
                                break;
                            }
                            case 2:{
                                estado_pedido=2;
                                break;
                            }
                         }
                         break;
                     }

                }

                if(estado_pedido==2){
                    if(f_aprobacion==null){
                        f_aprobacion = pedido.getDatos_SV()[i].getF_aprobacion();
                    }else{
                        if (f_aprobacion.compareTo(pedido.getDatos_SV()[i].getF_aprobacion())<0){

                            f_aprobacion = pedido.getDatos_SV()[i].getF_aprobacion();
                        }

                    }

                    if(pedido.getDatos_SV()[i].getF_provision()==null){
                        pedido_provisionado = false;
                    }
                    if(f_provision == null){
                        pedido.getDatos_SV()[i].getF_provision();
                    }else{
                        if(pedido.getDatos_SV()[i].getF_provision().compareTo(f_provision)>0){
                            f_provision=pedido.getDatos_SV()[i].getF_provision();
                        }
                    }

                }

                String [] duracion = pedido.getDatos_SV()[i].getDuracion_contrato().split("");
                int cant=0;
                if(duracion[0].trim().isEmpty()){
                    cant=0;
                }else{
                    cant = Integer.parseInt(duracion[0].trim());
                }

                String unidad = duracion[1].trim().toUpperCase();


                if(unidad_duracion_contrato ==" "){
                    System.out.println("unidad_duracion_contrato es vacio y se llena");
                    unidad_duracion_contrato = unidad;
                    duracion_contrato = cant;
                    System.out.println("La duración de contrato es:"+cant);
                    System.out.println("La unidad de duracion de contrato es:"+unidad_duracion_contrato);
                }/*else{*/
                    /* if(unidad_duracion_contrato != unidad){
                         System.out.println("Esto es lo que me falla donde unidad_duracion_contrato es:"+unidad_duracion_contrato +" y unidad es:"+unidad);
                     }
                    if (unidad_duracion_contrato != unidad || duracion_contrato != cant){
                        throw new Exception ("Pedido con diferentes duraciones de contrato: "+key);
                    }*/
                /*}*/
                System.out.println("Voy a hacer el insert de los servidores virtuales");    


                int ejecutadoServiVirtual =  pstmSv.executeUpdate();
                System.out.println("ejecutadoServiVirtual es:"+ejecutadoServiVirtual);
                if(ejecutadoServiVirtual==0){                         
                    throw new Exception("Error al grabar Pedidos");

             }
                ResultSet rsServ = pstmSv.getGeneratedKeys(); 

                if (rsServ != null && rsServ.next()) { 
                  int  keyServidorV = rsServ.getInt(1);
                  System.out.println("El keyServidorV es:"+keyServidorV);
                } 



                /*for(int h=0;h< pedido.getDatos_SV().length;h++){

                    System.out.println("h---------->"+h);*/
                    switch (metodo_facturacion){
                        case 1: //DIODE
                        case 2: //DIRECTO 
                        {
                              TDatosRetorno result_coste = insertar_PrecioCoste_SV(pedido.getDatos_SV()[i].getId_servidor_virtual(),pedido.getDatos_SV()[i].getPlantilla(),pedido.getDatos_SV()[i].getDisco_almacenamiento(),proveedor);

                              if(result_coste.getError()==-1){
                                  throw new Exception(result_coste.getDescripcion_error());

                              }
                              break;
                        }
                    }
                /*}*/


                int ind =0;

                /*for(int z =0;z<pedido.getDatos_SV().length;z++){  */ //Meter sa dentro de servidores virtuales

                    if(pedido.getDatos_SV()[i].getDatos_servicios_adicionales()!=null){  

                        SQL="INSERT INTO servicios_adicionales (id_servicio_adicional,id_servidor_virtual,sku,descripcion,cantidad,unidad,pvp,unidad_dist,pvp_dist,base_pvp,base_pvp_dist) VALUES(?,?,?,?,?,?,?,?,?,?,?)";

                           PreparedStatement pstmSA = this.conexion.prepareStatement(SQL,PreparedStatement.RETURN_GENERATED_KEYS);
                           for(int k=0;k<pedido.getDatos_SV()[i].getDatos_servicios_adicionales().length;k++){
                                servID[i]=pedido.getDatos_SV()[i].getId_servidor_virtual();
                                System.out.println("k------------>"+k);

                                pstmSA.setInt(1, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getId_servicios_adicionales());
                                pstmSA.setInt(2, pedido.getDatos_SV()[i].getId_servidor_virtual());  //Nuestro lastinsert
                                System.out.println("SKU----->"+pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getSku());
                                pstmSA.setString(3, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getSku());
                                System.out.println("Descripción---->"+pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getDescripcion());
                                pstmSA.setString(4, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getDescripcion());
                                pstmSA.setInt(5, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getCantidad());
                                pstmSA.setString(6, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getUnidad());
                                pstmSA.setDouble(7, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getPvp());
                                pstmSA.setString(8, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getUnidad_dist());
                                pstmSA.setDouble(9, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getPvp_dist());
                                pstmSA.setDouble(10, pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getBase_pvp());
                                pstmSA.setDouble(11,pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getBase_pvp_dist());

                                ind++;

                               System.out.println("Voy a ejecutandoSA ");
                                int ejecutadoSA =  pstmSA.executeUpdate();
                                if(ejecutadoSA==0){ 
                                   throw new Exception("Error al grabar envíos Servicios Adicionales");
                                }


                                ResultSet rsSA = pstmSA.getGeneratedKeys(); 
                                int  keyServidorA=0;
                                if (rsSA != null && rsSA.next()) { 
                                    keyServidorA = rsSA.getInt(1); 

                                }



                                /*for(int k=0;k<pedido.getDatos_SV()[i].getDatos_servicios_adicionales().length;k++){*/

                                       switch(metodo_facturacion){
                                          case 1:// DIODE
                                          case 2: //DIRECTA 
                                          {

                                              //System.out.println("keyServidorA es:"+keyServidorA);
                                              System.out.println("Sku es------------->"+pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getSku());
                                              TDatosRetorno result_coste = insertar_precioCoste_SA(pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getId_servicios_adicionales(),pedido.getDatos_SV()[i].getDatos_servicios_adicionales()[k].getSku(),1);

                                              if(result_coste.getError() == -1){
                                                  throw new Exception (result_coste.getDescripcion_error());
                                              }
                                              break;
                                          }
                                       }
                                   /*}*/





                           }



                    }
                /*}*/
                System.out.println("He acabado de grabar servicios adicionales");





         }







        }else{
            throw new Exception("Pedido sin servidores virtuales:"+pedido.getId_pedido());  
        }
        System.out.println("El método de facturación es:"+metodo_facturacion);
        switch(metodo_facturacion){

            case 1:{
                System.out.println("Estado_Pedido es_"+estado_pedido);
                if(estado_pedido == 1 || estado_pedido == 2){

                    if(pedido.isEs_actualizacion()){
                        f_inicio_contrato = pedido.getF_creacion();
                        f_fin_contrato = obtener_fecha_fin_contrato(pedido.getId_pedido_actualizado());
                    }else{
                        System.out.println("f_aprobacion es:"+f_aprobacion);
                        if(f_aprobacion == null)
                            f_inicio_contrato = pedido.getF_creacion();
                        else
                            f_inicio_contrato = f_aprobacion;
                        System.out.println("Unidad_duracion_contrato es:"+unidad_duracion_contrato);
                        switch(unidad_duracion_contrato){

                        case "DAY":{
                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                               calDays.add(Calendar.DATE, duracion_contrato);   
                               f_fin_contrato = calDays.getTime();
                               break;
                           }
                           case "WEEK":{

                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                               calDays.add(Calendar.DATE, duracion_contrato*7);     
                               f_fin_contrato = calDays.getTime();
                               break;
                           }
                           case "MONTH":{
                               System.out.println("Estoy en mes y la duracion de contrato es:"+duracion_contrato);
                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                               calDays.add(Calendar.MONTH, duracion_contrato);  
                                f_fin_contrato = calDays.getTime();
                                System.out.println("El fin de contrato es:"+f_fin_contrato);
                               break;
                           }
                           case "YEAR":{
                              Calendar calDays = Calendar.getInstance(); 
                              calDays.setTime(f_inicio_contrato); 
                              calDays.add(Calendar.YEAR, duracion_contrato); 
                              f_fin_contrato = calDays.getTime();
                              break;
                           }
                        }
                    }

                    if(pedido_provisionado){
                        estado_pedido = 3;
                    }
                }
                break;
            } 
            case 2:{
                if(estado_pedido == 2){

                    if(pedido.isEs_actualizacion()){
                        f_inicio_contrato = pedido.getF_creacion();
                        f_inicio_contrato = obtener_fecha_fin_contrato(pedido.getId_pedido_actualizado());
                    }else{
                        System.out.println("f_aprobacion es:"+f_aprobacion);
                        if(f_aprobacion == null){
                            System.out.println("f_aprobacion es nulo entonces hay"+pedido.getF_creacion());
                            f_inicio_contrato = pedido.getF_creacion();
                        }   
                        else
                            f_inicio_contrato = f_aprobacion;

                        switch (unidad_duracion_contrato){
                           case "DAY":{
                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                                calDays.add(Calendar.DATE, duracion_contrato);  
                               f_fin_contrato = calDays.getTime();
                               break;
                           }
                           case "WEEK":{

                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                               calDays.add(Calendar.DATE, duracion_contrato*7);     
                               f_fin_contrato = calDays.getTime();
                               break;
                           }
                           case "MONTH":{

                               Calendar calDays = Calendar.getInstance(); 
                               calDays.setTime(f_inicio_contrato); 
                               calDays.add(Calendar.MONTH, duracion_contrato);  
                                f_fin_contrato = calDays.getTime();
                               break;
                           }
                           case "YEAR":{
                              Calendar calDays = Calendar.getInstance(); 
                              calDays.setTime(f_inicio_contrato); 
                              calDays.add(Calendar.YEAR, duracion_contrato); 
                              f_fin_contrato = calDays.getTime();
                              break;
                           }
                        }

                        if(pedido_provisionado){
                            estado_pedido = 3;
                        }
                    }

                }
                break;
              }
            } 






            int id_formato_documento;
            System.out.println("Voy a mandar un albarán a:"+pedido.getId_cuenta());
            Tcuenta cuenta_receptora = buscar_Cuenta(pedido.getId_cuenta());  
            if(cuenta_receptora.getCuenta()!= -1){  //Aquí había -1
                System.out.println("Cuenta receptora la cuenta padre es:"+cuenta_receptora.getCuenta_padre());
                Tcuenta cuenta_emisora = buscar_cuenta_emisora(cuenta_receptora.getCuenta_padre());
                while(cuenta_emisora.getCuenta()!=-1){  //Aquí había -1

                    if(cuenta_emisora.getNivel()==0){
                        id_formato_documento = 1;
                    }else{
                        id_formato_documento = 2;
                    }

                    TDatosRetorno result1 = grabarAlbaran(pedido.getId_pedido(),cuenta_emisora.getCuenta(),cuenta_receptora.getCuenta(),cuenta_receptora.getDescuento(),id_formato_documento);
                    if(result1.getError()==-1){                  //Nuestro
                        throw new Exception(result1.getDescripcion_error());
                    }
                    cuenta_receptora = cuenta_emisora;

                    cuenta_emisora = buscar_cuenta_emisora(cuenta_receptora.getCuenta_padre()); //Tipo String n_cuenta_padre
                    System.out.println("Cuenta receptora es:"+cuenta_receptora.getCuenta());
                }
            }else{
                throw new Exception("La cuenta del pedido: "+pedido.getId_cuenta()+"no existe");
            }

                TDatosRetorno result;
            for(int x=0;x<servID.length;x++){
                System.out.println(servID[x]);
                if(servID[x]!=0){
                    result = generar_lineas_albaran(pedido,pedido.getId_pedido(),metodo_facturacion,servID[x]);
                    if(result.getError()==-1){
                        throw new Exception(result.getDescripcion_error());
                    }
                }
            } 


                System.out.println("Voy a hacer el update de los pedidos");
                SQL = "UPDATE pedidos SET ";

                if(f_aprobacion != null){

                    SQL=SQL+" f_aprobacion = ?,";
                }

                if((metodo_facturacion == 1)||(metodo_facturacion == 2 && (estado_pedido == 2 || estado_pedido == 3))){

                    SQL = SQL +"f_inicio_contrato = ?,f_fin_contrato=?,";
                }

                SQL = SQL +"id_estado_pedido = ? WHERE id_pedido = ?";
                System.out.println("EL SQL DEL UPDATE ES:"+SQL);
                PreparedStatement pstmAct = this.conexion.prepareStatement(SQL);
                if((f_aprobacion!=null)&&(((metodo_facturacion == 1)||(metodo_facturacion == 2 && (estado_pedido == 2 || estado_pedido == 3))))){
                    System.out.println("Dentro de if de f_aprobacion");


                    java.sql.Date f_aprobacionAux = new java.sql.Date(f_aprobacion.getTime());
                    pstmAct.setDate(1, f_aprobacionAux);

                    java.sql.Date f_inicio_contratoAux = new java.sql.Date(f_inicio_contrato.getTime());
                    pstmAct.setDate(2, f_inicio_contratoAux);
                    java.sql.Date f_fin_contratoAux = new java.sql.Date(f_fin_contrato.getTime());
                    pstmAct.setDate(3, f_fin_contratoAux);
                    pstmAct.setInt(4, estado_pedido);
                    pstmAct.setInt(5, pedido.getId_pedido());  // Pedido mío?

                }

                if((f_aprobacion==null)&&(((metodo_facturacion == 1)||(metodo_facturacion == 2 && (estado_pedido == 2 || estado_pedido == 3))))){
                    System.out.println("Dentro de if de f_aprobacion");

                    java.sql.Date f_inicio_contratoAux = new java.sql.Date(f_inicio_contrato.getTime());
                    pstmAct.setDate(1, f_inicio_contratoAux);
                    java.sql.Date f_fin_contratoAux = new java.sql.Date(f_fin_contrato.getTime());
                    pstmAct.setDate(2, f_fin_contratoAux);
                    pstmAct.setInt(3, estado_pedido);
                    pstmAct.setInt(4, pedido.getId_pedido());  // Pedido mío?

                }


                int ejecutadoPed =  pstmAct.executeUpdate();
                if(ejecutadoPed==0){    
                   throw new Exception("Error al actualizar Pedidos");
                }

                if(pedido.getDatos_cuentas()!=null){

                    for(int i = 0; i <pedido.getDatos_cuentas().length;i++){

                        TDatosRetorno result2 = actualizarCuenta(pedido.getDatos_cuentas()[i], true, false, true);

                        if(result2.getError()==-1){
                            throw new Exception(result2.getDescripcion_error());

                        }
                    }


                }



            this.conexion.commit();
            this.conexion.setAutoCommit(true);
            this.conexion.close();
            resultado.setError(0);
            resultado.setDescripcion_error("");
            return resultado;










        } catch (Exception e) {
        // TODO Auto-generated catch block

                e.printStackTrace();
                resultado.setError(-1);
                resultado.setDescripcion_error(e.getMessage());
                try {
                    this.conexion.rollback();
                    this.conexion.setAutoCommit(true);
                } catch (SQLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                e.printStackTrace();
                return resultado;


    }





}   

What is wrong?.Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:01:51+00:00Added an answer on June 17, 2026 at 12:01 pm

    Database locks happen when there are uncommitted transactions pending. The database is waiting for an explicit rollback or commit.

    The table you are waiting on cluw.pedidos appears to have such a transaction.

    • check to see if there are other users holding an uncommitted transaction open
    • check to see if your own query tool is holding an open transaction (check the preferences of your query tool for auto-commit or something like that)
    • check the code of your application to see if a separate connection is still holding a transaction open

    Depending on the number of rows being impacted by the database transaction, database engines may introduce row-level-locking or table-level-locking on any other changes until the transaction is completed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the given view and template code, when i try to run this
This Java code compiles fine, but when I try to run it I get:
When I try to run this code, I get incorrect maximums and minimums. Could
Thanks in advance. This is my sample code. Whenever i try to run it
I have this code that I wrote in python: from Purchase import Transaction from
I am trying to have this code run and delete a certain record in
I have this below code to retrieve data from db and when I run
When I try to run my code on any other webbrowsers apart from the
I try to run the following code: public void Init(Url rootUrl) { var web
When I try to run the following code from the REPL (playing with dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.