0

Tengo un problema y eso que después de probar varios plugins como POI no consigo pasar una base de datos a un fichero Excel.

        /**
         * 
         * @param event
         */
        @FXML
        void GuardarbbddExcel(ActionEvent event) {
    
            // ConvertirAExcel.export();
    
            FileChooser fileChooser = new FileChooser();
            File fichero = fileChooser.showSaveDialog(null);
    
            try {
                HSSFWorkbook hwb = new HSSFWorkbook();
                HSSFSheet sheet = hwb.createSheet("new sheet");
    
                HSSFRow rowhead = sheet.createRow((short) 0);
                rowhead.createCell((short) 0).setCellValue("Nombre");
                rowhead.createCell((short) 1).setCellValue("Numero");
                rowhead.createCell((short) 2).setCellValue("Variante");
                rowhead.createCell((short) 3).setCellValue("Firma");
                rowhead.createCell((short) 4).setCellValue("Editorial");
                rowhead.createCell((short) 5).setCellValue("Formato");
                rowhead.createCell((short) 6).setCellValue("Procedencia");
                rowhead.createCell((short) 7).setCellValue("Publicacion");
                rowhead.createCell((short) 8).setCellValue("Guionista");
                rowhead.createCell((short) 9).setCellValue("Dibujante");
    
                Statement st = conn.createStatement();
                ResultSet rs = st.executeQuery("Select * from comicsbbdd");
                int i = 1;
                while (rs.next()) {
                    HSSFRow row = sheet.createRow((short) i);
                    row.createCell((short) 0).setCellValue(rs.getString("nombreCom"));
                    row.createCell((short) 1).setCellValue(rs.getString("numeroCom"));
                    row.createCell((short) 2).setCellValue(rs.getString("varianteCom"));
                    row.createCell((short) 3).setCellValue(rs.getString("firmaCom"));
                    row.createCell((short) 4).setCellValue(rs.getString("editorialCom"));
                    row.createCell((short) 5).setCellValue(rs.getString("formatoCom"));
                    row.createCell((short) 6).setCellValue(rs.getString("procedenciaCom"));
                    row.createCell((short) 7).setCellValue(rs.getString("fechaCom"));
                    row.createCell((short) 8).setCellValue(rs.getString("guionistaCom"));
                    row.createCell((short) 9).setCellValue(rs.getString("dibujanteCom"));
                    i++;
                }
                FileOutputStream fileOut = new FileOutputStream(fichero);
                hwb.write(fileOut);
                fileOut.close();
                hwb.close();
                labelDatosGuardados.setStyle("-fx-background-color: #F53636");
                labelDatosGuardados.setText("Se ha generado el Excel correctamente");
    
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }

El error que me salta es este:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at [email protected]/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857) at [email protected]/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724) at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at [email protected]/javafx.event.Event.fireEvent(Event.java:198) at [email protected]/javafx.scene.Node.fireEvent(Node.java:8797) at [email protected]/javafx.scene.control.Button.fire(Button.java:203) at [email protected]/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208) at [email protected]/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274) at [email protected]/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247) at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234) at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at [email protected]/javafx.event.Event.fireEvent(Event.java:198) at [email protected]/javafx.scene.Scene$MouseHandler.process(Scene.java:3881) at [email protected]/javafx.scene.Scene.processMouseEvent(Scene.java:1874) at [email protected]/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607) at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411) at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450) at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424) at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449) at [email protected]/com.sun.glass.ui.View.handleMouseEvent(View.java:551) at [email protected]/com.sun.glass.ui.View.notifyMouse(View.java:937) at [email protected]/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at [email protected]/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:316) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:577) at [email protected]/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275) at [email protected]/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84) at [email protected]/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1852) ... 46 more Caused by: java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook at Controladores.VerComicController.GuardarbbddExcel(VerComicController.java:365) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ... 53 more Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 55 more

Tengo instaladas las librerías de POI, no me dan fallo a la hora de poner el código, solo a hacer funcionar el programa. PD: La base de datos quiero que tenga su etiqueta de que es, por eso he creado los rowhead, para que inserten esas tablas y después el contenido de la base de datos.

2
  • 2
    Esta es su respuesta "java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook" en medio de su stacktrace, necesita la versión de apache-poi que tiene esta clase, abra su jar POI con un 7zip o similar y verifique si la clase está allí, si no, necesita otro jar, si está allí, el jar no está configurado correctamente en su classpath
    – res
    Commented el 16 jun. 2022 a las 14:18
  • ¿Responde esto a tu pregunta? A que se debe el error de tipo NoClassDefFoundError?
    – Alfabravo
    Commented el 17 jun. 2022 a las 16:51

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.