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();
    }
 }
}

posted on 2008-01-08 20:08 灵! 阅读(269) 评论(0)  编辑  收藏 所属分类: Java技术-报表


只有注册用户登录后才能发表评论。


网站导航:
 
<2008年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

随笔分类

随笔档案

最新评论

阅读排行榜

评论排行榜