朋的博客

MySQL资料,Java技术,管理思想,博弈论,Ajax,XP极限编程,H.264,HEVC,HDR
随笔 - 86, 文章 - 59, 评论 - 1069, 引用 - 0
数据加载中……

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 2005-07-11 21:31 benchensz 阅读(919) 评论(1)  编辑  收藏 所属分类: Java技术

评论

# re: iReport 报表在应用程序中的应用代码(转载)  回复  更多评论   

我是初学者,请多多指点,编译也不通过呀!
这里 mgr.setMonitorThread(520); 编辑器就出现问题啦,是不是要导入什么类呀
2006-02-09 14:59 | sosynu@sohu.com

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


网站导航: