- 作者:zhaozj
- 发表时间:2020-12-23 10:38
- 来源:未知
下面的代码是我在用ireport做报表,应用在应用程序中的代码,应用程序可以引用这个类,完成报表打印
预览:有问题请联系我!!!一起探讨!
import dori.jasper.engine.*;import dori.jasper.engine.util.*;import java.sql.*;import java.util.*;import dori.jasper.engine.JasperReport;import java.util.Date;import java.text.SimpleDateFormat;import dori.jasper.view.*;import org.apache.commons.logging.LogFactory;import com.lowagie.text.DocumentException;import com.lowagie.text.*;import dori.jasper.engine.design.*;import org.apache.commons.digester.Digester;import org.apache.commons.beanutils.BeanUtils;
public class myreport{ public void reportName(String strBbmc) { JRResultSetDataSource jrds = null; JasperPrint jasperPrint = null; Map reportParams = new HashMap(); ResultSet rs = null; Connection con = null; Statement stmt = null; String sql = "select * from bbmc"; try { //动态获取 JasperDesign jasperDesign = JasperManager.loadXmlDesign("./bbmc.jrxml"); JasperReport jasperreport = JasperManager.compileReport(jasperDesign); //建立连接 ConnectionpoolManager mgr = new ConnectionpoolManager(); mgr.setMonitorThread(520); mgr.addAlias("jdbcConnecpool","com.microsoft.jdbc.sqlserver.SQLServerDriver","jdbc:microsoft:sqlserver://192.168.45.233:1433;DatabaseName = ysgl ","sa","sa",10,300,520,30,false); con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX+ConnectionPoolManager.getPoolName(),null,null); stmt = con.creatStatement(); rs = stmt.executeQuery(sql); jrds = new JRResultSetDataSource(rs); jasperPrint = JasperFillManager.fillReport(jasperReport,reportParams,jrds); //调出JasperViewer进行打印预览 JasperViewer.viewReport(jasperPrint); } catch(ClassNotFoundException ee) { ee.printStackTrace(); } catch(SQLException ex) { ex.pritStackTrace; } catch(JRException e) { e.getMessage(); } }}