1

Problem with report in mvc, zk, and postgresql

asked 2013-02-19 03:32:33 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-19 05:34:44 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hi good night! I'm working with MVC pattern. I need to create some reports with zk, ireport and postgresql. This is the java code: Controller:

package org.zkforge.Controlador;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.extensions.ExtensionsEnvironment; 
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;


import org.zkforge.Controlador.Catalogo;
import org.zkforge.Modelo.ConexionBD;
import org.zkforge.Modelo.ModEstado;
import org.zkforge.Modelo.ConsultasDataSource;
import org.zkforge.Modelo.ModMunicipio;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zkex.zul.Jasperreport;
import org.zkoss.zul.Button;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

public void onClick$btnImprimir() throws InterruptedException{
        Jasperreport reporte = new Jasperreport();
        reporte.setSrc("reporte_estado.jasper");
        List<String[]> lista = new ArrayList<String[]>();
        ConexionBD con = new ConexionBD();
        con.conectar();
        ResultSet rs = con.query("select * from \"estado\" where existe_es=true order by nombre_es");
        if(rs!=null) {
            try {
                while (rs.next()){
                String[] a =  {rs.getString("cod_edo"),rs.getString("nombre_es"),rs.getString("descripcion_es"),rs.getString("existe_es")};
                lista.add(a);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else {
            Messagebox.show("No existen registros en la base de datos para realizar la impresi�n","Informaci�n",Messagebox.OK,Messagebox.INFORMATION);
            return;

        }



        String[] lista2 = {"cod_edo","nombre_es","descripcion_es","existe_es"};
        Map parameters = new HashMap();

        //AGREGAR LA SIGUIENTE LINEA DE CODIGO PARA IMPRIMIR
        reporte.setParameters(parameters);
        reporte.setDatasource(new ConsultasDataSource(lista,lista2));
        Window w = new Window();
        w = (Window) Executions.createComponents("/Vista/InformacionPreliminar/reportes.zul", null, null);
        w.setTitle("Reporte de Estados");
        w.setClosable(true);
        w.doHighlighted();
        w.appendChild(reporte); 

    }

I call the function at the button "imprimir" in the .zul file like this:

<button id="btnImprimir"  tooltiptext="Imprimir" image="/images/ico/window_buttons/printer.png"/><space/>

When I press the button "imprimir" its open a report but it gave me a "null" value in the fields so I can't see the information.

I get the next error in the console:

org.postgresql.util.PSQLException: No results were returned by the query. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:253) at org.zkforge.Modelo.ConexionBD.query(ConexionBD.java:106) at org.zkforge.Modelo.ConexionBD.conectar(ConexionBD.java:49) at org.zkforge.Controlador.ContEstado.onClick$btnImprimir(ContEstado.java:115) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2723) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:308) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:331) at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3179) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1699) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1484) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1201) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:558) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:456) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:464) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) org.postgresql.util.PSQLException: No results were returned by the query. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:253) at org.zkforge.Modelo.ConexionBD.query(ConexionBD.java:106) at org.zkforge.Modelo.ConexionBD.conectar(ConexionBD.java:55) at org.zkforge.Controlador.ContEstado.onClick$btnImprimir(ContEstado.java:115) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2723) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:308) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:331) at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3179) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1699) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1484) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1201) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:558) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:456) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:464) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

So I you can Help me I'll be really glad!

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
1

answered 2013-02-19 05:33:23 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-19 05:35:40 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

See this Integrate Dyanmic Jasper Reprot with ZK may be this blog will help you to resolve your issue, also check if your query returning any result or not?

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-02-19 03:32:33 +0800

Seen: 28 times

Last updated: Feb 19 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More