日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

水晶报表for java_水晶报表(crystal reports)--java

發(fā)布時間:2023/12/14 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 水晶报表for java_水晶报表(crystal reports)--java 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這兩天項目要用水晶報表(crystal reports),上網(wǎng)查了下資料,網(wǎng)上的資料不是太多.

1.安裝

首先用的時候先到官網(wǎng)(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取數(shù)和數(shù)據(jù)庫連接

有兩種方式

第一種:

1)

這個帶出來的實例。CrystalReport1.rpt 可以在Eclipse直接去連接數(shù)據(jù)庫表和視圖。直接把

數(shù)據(jù)取出來不做任何修改的展示。

我這里使用POJO的方式來做報表。以滿足日常中在JAVA做數(shù)據(jù)處理后。做報表的顯示。

首先建立和數(shù)據(jù)庫表一樣名字的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 + "]";

}

}

建立與數(shù)據(jù)庫連接的類

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:端口/數(shù)據(jù)庫名稱?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();

}

}

}

建立取數(shù)的DAO接口

package com.businessobjects.samples;

import java.util.List;

/**

* 取數(shù)據(jù)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;

/**

* 根據(jù)ID查詢操作

* @param id

* @return

* @throws Exception

*/

public Person queryById(int id)throws Exception;

/**

* 查詢?nèi)?/p>

* @return ?persons

* @throws Exception

*/

public List queryAll() throws Exception;

/**

* 模糊查詢

* @param cond

* @return persons

* @throws Exception

*/

public List queryByLike(String cond)throws Exception;

}

對接口寫實現(xiàn)。該處只做QUERYALL的實現(xiàn)。作為示例

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{

//連接數(shù)據(jù)庫

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("查詢出現(xiàn)異常");

}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的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。