这两天项目要用水晶报表(crystal reports),上网查了下资料,网上的资料不是太多.

1.安装

首先用的时候先到官网(https://www.sap.com/china/product/analytics/crystal-reports-eclipse.html)下载插件(SAP Crystal Reports(Eclipse 版))集成到eclipse中 ,下载之后解压

将文件放到eclipse相应的文件夹下。重启eclipse!

2.建项目

eclipse右键新建项目,选择Crystal Reports Web Project

输入项目名

finaish,项目结构展示如下:

3.建立java取数和数据库连接

有两种方式

第一种:

1)

这个带出来的实例。CrystalReport1.rpt 可以在Eclipse直接去连接数据库表和视图。直接把

数据取出来不做任何修改的展示。

我这里使用POJO的方式来做报表。以满足日常中在JAVA做数据处理后。做报表的显示。

首先建立和数据库表一样名字的POJO Person.java

package com.businessobjects.samples;

import java.util.Date;

public class Person {

private int id;

private String t_name;

private String password;

private Date birthday;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getT_name() {

return t_name;

}

public void setT_name(String t_name) {

this.t_name = t_name;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

public Person() {

}

public Person(int id, String t_name, String password, Date birthday) {

super();

this.id = id;

this.t_name = t_name;

this.password = password;

this.birthday = birthday;

}

@Override

public String toString() {

return "Person [id=" + id + ", t_name=" + t_name + ", password="

+ password + ", birthday=" + birthday + "]";

}

}

建立与数据库连接的类

package com.businessobjects.samples;

import java.sql.Connection;

import java.sql.DriverManager;

public class DataBaseConnection {

private final String DBDRIBER ="com.mysql.jdbc.Driver";

private final String DBURL = "jdbc:mysql://IP:端口/数据库名称?useUnicode=true&characterEncoding=utf8";

private final String DBUSER = "用户";

private final String DBPASSWORD = "密码";

private Connection  conn= null;

public DataBaseConnection(){

try{

Class.forName(DBDRIBER);

this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);

}catch(Exception e){

e.printStackTrace();

}

}

public Connection getConnection(){

return this.conn;

}

public void close(){

try{

this.conn.close();

}catch(Exception e){

e.printStackTrace();

}

}

}

建立取数的DAO接口

package com.businessobjects.samples;

import java.util.List;

/**

* 取数据DAO接口

* @author Scaler_Zhang

*

*/

public interface IPersonDao {

/**

* 添加操作

* @param person 用户信息

* @throws Exception

*/

public void insert(Person person)throws Exception;

/**

* 更新操作

* @param person

* @throws Exception

*/

public void update(Person person)throws Exception;

/**

* 删除操作

* @param person

* @throws Exception

*/

public void delete(Person person)throws Exception;

/**

* 根据ID查询操作

* @param id

* @return

* @throws Exception

*/

public Person queryById(int id)throws Exception;

/**

* 查询全部

* @return  persons

* @throws Exception

*/

public List queryAll() throws Exception;

/**

* 模糊查询

* @param cond

* @return persons

* @throws Exception

*/

public List queryByLike(String cond)throws Exception;

}

对接口写实现。该处只做QUERYALL的实现。作为示例

package com.businessobjects.samples;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import java.util.List;

public class PersonDao implements IPersonDao {

public void insert(Person person) throws Exception {

// TODO Auto-generated method stub

}

public void update(Person person) throws Exception {

// TODO Auto-generated method stub

}

public void delete(Person person) throws Exception {

// TODO Auto-generated method stub

}

public Person queryById(int id) throws Exception {

// TODO Auto-generated method stub

return null;

}

public List queryAll() throws Exception {

List all = new ArrayList();

String sql = "select * from person";

PreparedStatement stat = null;

DataBaseConnection dbc = null;

try{

//连接数据库

dbc = new DataBaseConnection();

stat = dbc.getConnection().prepareStatement(sql);

ResultSet rst = stat.executeQuery();

while(rst.next()){

Person person = new Person();

person.setId(rst.getInt(1));

person.setT_name(rst.getString(2));

person.setPassword(rst.getString(3));

person.setBirthday(rst.getDate(4));

all.add(person);

}

}catch(Exception e){

e.printStackTrace();

throw new Exception("查询出现异常");

}finally{

dbc.close();

}

return all;

}

public List queryByLike(String cond) throws Exception {

// TODO Auto-generated method stub

return null;

}

}

这样整体就写完了。

2)建立报表

右击项目选择

建立一张空白报表。在报表视图里把下如蓝色标记的地方拖到 Data 的空白部分

设计报表一张简单的报表,从右侧选择要展示的字段,直接拖到展示的地方

选择如下

OK,生成jsp代码如下

com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,

com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,

com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase" %>

// This sample code calls methods from the CRJavaHelper class, which

// contains examples of how to use the BusinessObjects APIs. You are free to

// modify and distribute the source code contained in the CRJavaHelper class.

try {

String reportName = "Person.rpt";

ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);

if (clientDoc == null) {

// Report can be opened from the relative location specified in the CRConfig.xml, or the report location

// tag can be removed to open the reports as Java resources or using an absolute path

// (absolute path not recommended for Web applications).

clientDoc = new ReportClientDocument();

clientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);

// Open report

clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);

// ****** BEGIN POPULATE WITH RESULTSET SNIPPET ****************

{

// This option is not applicable for the report you have chosen

}

// ****** END POPULATE WITH RESULTSET SNIPPET ****************

// ****** BEGIN POPULATE WITH POJO SNIPPET ****************

{

// This option is not applicable for the report you have chosen

}

// ****** END POPULATE WITH POJO SNIPPET ****************

// Store the report document in session

session.setAttribute(reportName, clientDoc);

}

// ****** BEGIN CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************

{

// Create the CrystalReportViewer object

CrystalReportViewer crystalReportPageViewer = new CrystalReportViewer();

String reportSourceSessionKey = reportName+"ReportSource";

Object reportSource = session.getAttribute(reportSourceSessionKey);

if (reportSource == null)

{

reportSource = clientDoc.getReportSource();

session.setAttribute(reportSourceSessionKey, reportSource);

}

//    set the reportsource property of the viewer

crystalReportPageViewer.setReportSource(reportSource);

// Apply the viewer preference attributes

// Process the report

crystalReportPageViewer.processHttpRequest(request, response, application, null);

}

// ****** END CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************

} catch (ReportSDKExceptionBase e) {

out.println(e);

}

%>

运行项目访问页面就可以看到展示的报表了

第二种:

https://my.oschina.net/u/2391879/blog/886847

水晶报表for java_水晶报表(crystal reports)--java相关推荐

  1. Stimulsoft Reports.Java 2022.2.3 Crack

    Stimulsoft Reports.Java Stimulsoft Reports.Java 是一个报告工具,专为在 Java 应用程序中设计报告而设计. Java 报告生成器 Stimulsoft ...

  2. bdm导入mysql_vs 2010下使用水晶报表Crystal Reports

    vs 2010下使用水晶报表Crystal Reports 的详细步骤 一.所需条件 1. 工作环境 VS 2010(页面和报表文件要在不同文件夹),对VS 2008,VS 2005 也可. 2. 数 ...

  3. 报表学习总结(一)——ASP.NET 水晶报表(Crystal Reports)的简单使用

    报表学习总结(一)--ASP.NET 水晶报表(Crystal Reports)的简单使用 目录 一.水晶报表简介 二.水晶报表的实现模式 2.1.拉(PULL)模式 2.1.1.不敲一句代码创建水晶 ...

  4. [水晶报表]如何设置水晶报表(crystal reports)的字段自动换行

    在做报价系统时候水晶报表做最后报表的产出.由于规格字数较长,用户在预览报表时无法看全规格,规格多出部分会导致重叠现象. 百度文库提供一个解决方案: 1.如何设置水晶报表(crystal reports ...

  5. 水晶报表(crystal reports)--java

    这两天项目要用水晶报表(crystal reports),上网查了下资料,网上的资料不是太多. 1.安装     首先用的时候先到官网(https://www.sap.com/china/produc ...

  6. 水晶报表Crystal Reports XI服务器版

    Crystal Reports-可协助用户在企业网站或应用系统中设计.管理以及发布报表.水晶报表为企业提供了一个扎实的商业智能(Business Intelligence)的起始点,将零散的重要信息通 ...

  7. 水晶报表 Crystal Reports Crystalreports 技术论坛

    水晶报表 Crystal Reports Crystalreports 技术论坛 链接:http://bbs.crystal.softonline.com.cn/forumdisplay.php?fi ...

  8. vs 2010下使用水晶报表Crystal Reports

    vs 2010下使用水晶报表Crystal Reports (2013-04-26 10:34:41) vs 2010下使用水晶报表Crystal Reports 的详细步骤 一.所需条件 1. 工作 ...

  9. vs 2008 winfrom 水晶报表使用Crystal Reports

    在管理系统中,打印是不可缺少的一种功能.而市场上也有各种各样的打印工具报表,其中以SAP公司的水晶报表最为出名,且其功能强大,开发也方便.在VS开发环境中现在已经不集成了,但是可以自己下载安装 . 工 ...

  10. 水晶报表的统计功能-Crystal Report Sub total Per Page

    先大概表述下我对水晶报表的理解: 大体上Crystal Report 可以理解为3部分: 第一部分:数据引擎 Crystal Report 集成了各种数据访问接口,可以方便的从数据仓库中提取数据,并把 ...

最新文章

  1. 处理机调度的性能准则
  2. 关于SQL 数据库表中的聚集索引和非聚集索引等
  3. Android典型界面设计(8) ——ViewPager+PagerSlidingTabStrip实现双导航
  4. 软考信息安全工程师学习笔记汇总
  5. 安卓bmi项目_搭载安卓系统的智能健康一体机:上禾SH-V20
  6. php3源码分析,ThinkPHP3.1.3源码分析(一) 入口文件分析
  7. 火山图 多个样本、_statTarget-基于QC样本的代谢组学数据校正
  8. Java 数组转字符串
  9. 前景检测算法(十三)--KDE2000
  10. steam令牌 未能连接到服务器,连接错误无法连接到steam网络怎么办 steam网络连接错误解决方法【图文】...
  11. python课程报告模板_《Python语言编程课程设计》课程设计报告模版
  12. 如何恢复SVN被删除文件、文件夹
  13. stm32-DCMI—OV2640摄像头
  14. 开发工具-vscode 使用技巧
  15. 《当我谈跑步时我谈些什么》:痛苦难以避免,而磨难可以选择
  16. 深度学习基础之图像分类
  17. Squid代理服务器及配置
  18. 亲测bitLock再次上锁方法
  19. iOS UIDocumentPickerViewController页面列表底部有一截空白【已解决】
  20. Deep Compression, Song Han, Caffe 实现

热门文章

  1. 【经典箴言 || 人生感悟 】//wodeganwu3034 == 8. 回溯做过的事情,如Review自己曾经写过的代码或者设计,思考为什么会这么做,有没有更好的方法==
  2. 乐优商城服务器部署_黑马乐优商城项目总结
  3. 对外汉语语料库有哪些_汉语国际教育之语料库分享
  4. 对外汉语偏误语料库_BCC语料库
  5. 昆仑通态触摸屏如何把参数由触摸屏传递到PLC_深圳PLC自动化培训哪家比较好
  6. eplan2.5安装教程
  7. Windows下连接Linux的ssh工具有哪些
  8. PLSQL下载及安装
  9. mysql更新记录_如何查看 mysql 表中最近更新的记录
  10. 黑群晖数据迁移白群晖(DS 920+)