stimulsoft mysql_【Stimulsoft Reports Java教程】在运行时使用MySQL数据库创建报表

stimulsoft mysql_【Stimulsoft Reports Java教程】在运行时使用MySQL数据库创建报表此示例项目显示如何使用MySQL字段创建新报表并提取MySQL数据库信息。首先,您需要创建一个新报表并添加MySqlDatabase。在StiMySqlDatabase类的构造函数中,您应该设置数据库名称,别名和连接字符串。publicstaticStiReportcreateReport()throwsClassNotFoundException,SQLException,StiE…

大家好,又见面了,我是你们的朋友全栈君。

此示例项目显示如何使用MySQL字段创建新报表并提取MySQL数据库信息。

首先,您需要创建一个新报表并添加MySqlDatabase。在StiMySqlDatabase类的构造函数中,您应该设置数据库名称,别名和连接字符串。

public static StiReport createReport() throws ClassNotFoundException, SQLException, StiException, FileNotFoundException {

StiReport report = StiReport.newInstance();

StiPage page = report.getPages().get(0);

report.setDictionary(new StiDictionary(report));

StiMySqlDatabase db = new StiMySqlDatabase(

“test”, “test&quot%t.setName(“DataText” + nameIndex.toString());

dataText.getBorder().setSide(StiBorderSides.All);

dataBand.getComponents().add(dataText);

pos = pos + columnWidth;

nameIndex++;

}

最后,使用报表对象的Render()方法呈现创建的报表,并返回结果。

report.Render();

return report;

}

要显示报表,我们使用本机Java查看器。我们需要创建查看器对象,添加必要的事件侦听器并分配报表。

public static void showReport(StiReport report) {

JFrame frame = new JFrame();

JPanel panel = new JPanel();

panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

panel.setPreferredSize(new Dimension(1000, 1000));

StiViewerFx viewerPanel = new StiViewerFx(frame);

panel.add(viewerPanel);

frame.add(panel);

frame.setSize(new Dimension(1000, 1000));

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

viewerPanel.getStiViewModel().getEventDispatcher()

.dispatchStiEvent(new StiViewCommonEvent(StiViewCommonEvent.DOCUMENT_FILE_LOADED, new StiDocument(report), null));

}

public static void main(String[] args) throws ClassNotFoundException, SQLException, StiException, FileNotFoundException {

StiReport report = createReport();

showReport(report);

}

示例代码的结果如下图所示:

833a2f0cccdde35bdcc5878573053740.png

购买Stimulsoft正版授权,请点击“咨询在线客服”哟!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158835.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号