简体   繁体   English

贾斯珀报告JAVA摇摆

[英]Jasper Report JAVA swing

I am trying to create a report using java swing that is able to print the data that I have on my SQL database, I found this after I googled my problem and I follow the step-by-step tutorial, everything goes smooth and no error occured, at first it seems fine but after I put these codes (that will generate the report that I want) : 我正在尝试使用java swing创建一个报告,该报告能够打印我在SQL数据库中的数据,我在对问题进行了搜索之后发现了这一点 ,并且按照分步教程进行操作,一切顺利并且没有错误发生,起初看起来还不错,但是在我输入了这些代码之后(将生成我想要的报告):

public void reportviewer() {
            try{
            String report = "C:\\Users\\cleanfuel\\Documents\\NetBeansProjects\\StringManipulation\\src\\stringmanipulation\\report1.jrxml";
            JasperReport jasp_report = JasperCompileManager.compileReport(report);
            JasperPrint jasp_print = JasperFillManager.fillReport(jasp_report, null, con);
            JasperViewer.viewReport(jasp_print);
            }
            catch (Exception e) {System.out.print(e);}
        }enter code here

After I run the program and clicking the buttong report, an error occured and print this : 在我运行程序并单击buttong报告后,发生了错误并打印此:

在此处输入图片说明

Can anyone tell me how to fix this one? 谁能告诉我如何解决这个问题? Did my I miss something? 我错过了什么吗?

Just create a log4j.properties and put it in your classpath: 只需创建一个log4j.properties并将其放在您的类路径中即可:

#
# connector logging configuration
#
# From most to least verbose: TRACE, DEBUG, INFO, WARN, ERROR, OFF
log4j.rootCategory=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p [%c{1}] - %m%n

Basically it's just log4j complaining that there are no appenders for it to output it's output to. 基本上,只是log4j抱怨没有附加器可将其输出到输出。

Unless you are really concerned about the output from Jasper Reports code, you don't need to worry about it to much. 除非您真的担心Jasper Reports代码的输出,否则您不必太担心。

If you want a quick fix, you could add the following to you code before you execute anything else. 如果需要快速修复,可以在执行其他任何操作之前将以下内容添加到代码中。

PatternLayout pl = new PatternLayout("[%-5p] %C.%M:%L: %m%n");
ConsoleAppender appender = new ConsoleAppender(pl);
Logger.getRootLogger().addAppender(appender);

It will basically add a console appender that will send the output to the console. 基本上,它将添加一个控制台附加程序,该附加程序会将输出发送到控制台。

Take a look at log4j for more details. 查看log4j了解更多详细信息。

Updated with example 更新了示例

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

public class Test {

    public static void main(String[] args) {
        PatternLayout pl = new PatternLayout("[%-5p] %C.%M:%L: %m%n");
        ConsoleAppender appender = new ConsoleAppender(pl);
        Logger.getRootLogger().addAppender(appender);
        // The rest of your code...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM