此示例项目显示如何使用MySQL字段创建新 表并提取MySQL数据库信息。
下载Stimulsoft Reports Java最新版本
此示例项目显示如何使用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"%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);}
示例代码的结果如下图所示:

下载示例
购买Stimulsoft正版授权,请点击“咨询在线客服”哟!
标签: 表JavaStimulsoft
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!