Foros del Web » Programación para mayores de 30 ;) » Java »

[SOLUCIONADO] java.sql.SQLException: Operation not allowed after ResultSet closed

Estas en el tema de java.sql.SQLException: Operation not allowed after ResultSet closed en el foro de Java en Foros del Web. Buenas tardes tengo el sgte codigo. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Java: Ver original public void agregarfacturaPedido ( String valor ) {           ...
  #1 (permalink)  
Antiguo 11/02/2015, 13:42
 
Fecha de Ingreso: enero-2015
Ubicación: Guayaquil
Mensajes: 17
Antigüedad: 9 años, 9 meses
Puntos: 0
Pregunta java.sql.SQLException: Operation not allowed after ResultSet closed

Buenas tardes tengo el sgte codigo.

Código Java:
Ver original
  1. public void agregarfacturaPedido(String valor) {  
  2.         try {
  3.             String nfac;
  4.             String fech;
  5.             String hora = guardarHora();
  6.             String codcli;
  7.             String nomcli;
  8.             String corcli;
  9.             String dircli;
  10.             String ruc;
  11.             String subt;
  12.             String desc;
  13.             String ivas;
  14.             String tot;
  15.             String usu;
  16.             String cliid;            
  17.                 valor = ProcesarPedidoGUI.cbPedido.getSelectedItem().toString();
  18.                 sql = "SELECT * FROM pedido WHERE ped_num_pedido = '" + valor + "'";
  19.                 cn = conectaMYSQL.getIntance().getConnection();
  20.                 st = cn.createStatement();                
  21.                 rs = st.executeQuery(sql);
  22.                 while (rs.next()) {
  23.                     nfac = ProcesarPedidoGUI.txtNumeroFactura.getText();
  24.                     System.out.print(rs.getString(3));
  25.                     fech = rs.getString(3);
  26.                     codcli = rs.getString(4);
  27.                     nomcli = rs.getString(5);
  28.                     corcli = rs.getString(6);
  29.                     dircli = rs.getString(7);
  30.                     ruc = rs.getString(8);
  31.                     subt = rs.getString(9);
  32.                     desc = rs.getString(10);
  33.                     ivas = rs.getString(11);
  34.                     tot = rs.getString(12);
  35.                     usu = "respinosa";
  36.                     muestraIdCli(seleccion, ProcesarPedidoGUI.lblCliId);
  37.                     cliid = ProcesarPedidoGUI.lblCliId.getText();
  38.                    
  39.                         cn = conectaMYSQL.getIntance().getConnection();
  40.                         cs = cn.prepareCall("{call Factura_Insertar(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
  41.                         cs.setString(1, nfac);
  42.                         cs.setString(2, fech);
  43.                         cs.setString(3, hora);
  44.                         cs.setString(4, codcli);
  45.                         cs.setString(5, nomcli);
  46.                         cs.setString(6, dircli);
  47.                         cs.setString(7, corcli);
  48.                         cs.setString(8, ruc);
  49.                         cs.setString(9, subt);
  50.                         cs.setString(10, desc);
  51.                         cs.setString(11, ivas);
  52.                         cs.setString(12, tot);
  53.                         cs.setString(13, usu);
  54.                         cs.setString(14, cliid);
  55.                         rpta = cs.executeUpdate();
  56.                         if (rpta == 1) {
  57.                             JOptionPane.showMessageDialog(null, "Factura Registrada Correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);
  58.                             numeros(ProcesarPedidoGUI.txtNumeroFactura);
  59.                             cargaRegistroPedido(ProcesarPedidoGUI.cbPedido, ProcesarPedidoGUI.lblMensaje);
  60.                         } else {
  61.                             JOptionPane.showMessageDialog(null, "Error Factura No Se Ingreso", "Aviso", JOptionPane.INFORMATION_MESSAGE);
  62.                         }                                        
  63.                 }
  64.               //  rs.close();
  65.             } catch (SQLException ex) {
  66.                 JOptionPane.showMessageDialog(null, ex.getMessage());
  67.                 Logger.getLogger(FacturaDAO.class.getName()).log(Level.SEVERE, null, ex);
  68.             }        
  69.     }

Pero me arroja cada vez que doy en guardar el sgte mensaje
Código Java:
Ver original
  1. java.sql.SQLException: Operation not allowed after ResultSet closed
  2.     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
  3.     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
  4.     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
  5.     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
  6.     at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:804)
  7.     at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6986)

Cual podria ser el error?
  #2 (permalink)  
Antiguo 12/02/2015, 01:54
Avatar de Profesor_Falken  
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 10 años, 2 meses
Puntos: 182
Respuesta: java.sql.SQLException: Operation not allowed after ResultSet closed

Buenas,

Si eliminas la parte del executeUpdate anidado te funciona?:

Código Java:
Ver original
  1. cn = conectaMYSQL.getIntance().getConnection();
  2.                         cs = cn.prepareCall("{call Factura_Insertar(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
  3.                         cs.setString(1, nfac);
  4.                         cs.setString(2, fech);
  5.                         cs.setString(3, hora);
  6.                         cs.setString(4, codcli);
  7.                         cs.setString(5, nomcli);
  8.                         cs.setString(6, dircli);
  9.                         cs.setString(7, corcli);
  10.                         cs.setString(8, ruc);
  11.                         cs.setString(9, subt);
  12.                         cs.setString(10, desc);
  13.                         cs.setString(11, ivas);
  14.                         cs.setString(12, tot);
  15.                         cs.setString(13, usu);
  16.                         cs.setString(14, cliid);
  17.                         rpta = cs.executeUpdate();

Un saludo
__________________
If to err is human, then programmers are the most human of us
  #3 (permalink)  
Antiguo 12/02/2015, 08:15
 
Fecha de Ingreso: enero-2015
Ubicación: Guayaquil
Mensajes: 17
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: java.sql.SQLException: Operation not allowed after ResultSet closed

Cita:
Iniciado por Profesor_Falken Ver Mensaje
Buenas,

Si eliminas la parte del executeUpdate anidado te funciona?:

Código Java:
Ver original
  1. cn = conectaMYSQL.getIntance().getConnection();
  2.                         cs = cn.prepareCall("{call Factura_Insertar(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
  3.                         cs.setString(1, nfac);
  4.                         cs.setString(2, fech);
  5.                         cs.setString(3, hora);
  6.                         cs.setString(4, codcli);
  7.                         cs.setString(5, nomcli);
  8.                         cs.setString(6, dircli);
  9.                         cs.setString(7, corcli);
  10.                         cs.setString(8, ruc);
  11.                         cs.setString(9, subt);
  12.                         cs.setString(10, desc);
  13.                         cs.setString(11, ivas);
  14.                         cs.setString(12, tot);
  15.                         cs.setString(13, usu);
  16.                         cs.setString(14, cliid);
  17.                         rpta = cs.executeUpdate();

Un saludo
Que tal resolví el inconveniente el problema radicaba en que la variable valor ya esta declarada global en le inicio del codigo y parece que el codigo interpretaba el valor que tenia la variable global y por lo tanto me generaba el error la solucion fue espicificar otro nombre a la variable y con eso me funciono.

Código Java:
Ver original
  1. public void agregarfacturaPedido(String val) {  
  2.         try {  
  3.             String nfac;
  4.             String fech;
  5.             String hora = facturaDAO.guardarHora();
  6.             String codcli;
  7.             String nomcli;
  8.             String corcli;
  9.             String dircli;
  10.             String ruc;
  11.             String subt;
  12.             String desc;
  13.             String ivas;
  14.             String tot;
  15.             String usu;
  16.             String cliid;            
  17.                 val = ProcesarPedidoGUI.cbPedido.getSelectedItem().toString();
  18.                 sql = "SELECT * FROM pedido WHERE ped_num_pedido = '" + val + "'";
  19.                 cn = conectaMYSQL.getIntance().getConnection();
  20.                 st = cn.createStatement();                
  21.                 rs = st.executeQuery(sql);
  22.                 while (rs.next()) {
  23.                     nfac = ProcesarPedidoGUI.txtNumeroFactura.getText();                    
  24.                     fech = rs.getString(3);
  25.                     codcli ="CC0002" ;
  26.                     nomcli = rs.getString(5);
  27.                     corcli = rs.getString(6);
  28.                     dircli = rs.getString(7);
  29.                     ruc = rs.getString(8);
  30.                     subt = rs.getString(9);
  31.                     desc = rs.getString(10);
  32.                     ivas = rs.getString(11);
  33.                     tot = rs.getString(12);
  34.                     usu = ProcesarPedidoGUI.lblUsuario.getText();                    
  35.                     seleccion = facturaDAO.muestraIdCliente(codcli);
  36.                     cliid = seleccion;
  37.                         cn = conectaMYSQL.getIntance().getConnection();
  38.                         cs = cn.prepareCall("{call Factura_Insertar(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
  39.                         cs.setString(1, nfac);
  40.                         cs.setString(2, fech);
  41.                         cs.setString(3, hora);
  42.                         cs.setString(4, codcli);
  43.                         cs.setString(5, nomcli);
  44.                         cs.setString(6, dircli);
  45.                         cs.setString(7, corcli);
  46.                         cs.setString(8, ruc);
  47.                         cs.setString(9, subt);
  48.                         cs.setString(10, desc);
  49.                         cs.setString(11, ivas);
  50.                         cs.setString(12, tot);
  51.                         cs.setString(13, usu);
  52.                         cs.setString(14, cliid);
  53.                         rpta = cs.executeUpdate();
  54.                         if (rpta == 1) {
  55.                             JOptionPane.showMessageDialog(null, "Factura Registrada Correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);                                                        
  56.                         } else {
  57.                             JOptionPane.showMessageDialog(null, "Error Factura No Se Ingreso", "Aviso", JOptionPane.INFORMATION_MESSAGE);
  58.                         }                                        
  59.                 }
  60.               //  rs.close();
  61.             } catch (SQLException ex) {
  62.                 JOptionPane.showMessageDialog(null, ex.getMessage());
  63.                 Logger.getLogger(FacturaDAO.class.getName()).log(Level.SEVERE, null, ex);
  64.             }        
  65.     }

Saludos.

Etiquetas: netbeans, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:26.