forked from demo/example
Compare commits
35 Commits
persist/10
...
release/10
Author | SHA1 | Date |
---|---|---|
Roger.Chen-陈旺 | 066849fb6f | 1 year ago |
roger | 4c97624bdc | 1 year ago |
roger | ee65b0dfe7 | 1 year ago |
Bruce.Deng-邓铖臻 | 737e4c42e5 | 2 years ago |
Bruce.Deng | 0614d33511 | 2 years ago |
Bruce.Deng | 504fd59217 | 2 years ago |
Bruce.Deng | d7737090ec | 2 years ago |
Bruce.Deng-邓铖臻 | 65312af3b2 | 2 years ago |
Bruce.Deng | 3f7ff140f8 | 2 years ago |
Rosie.Xu | f3f9a70b12 | 3 years ago |
Rosie.Xu | fb54bae1b0 | 3 years ago |
zack | 347a9332b8 | 3 years ago |
zack | 59aa0ad8be | 3 years ago |
zack | cddbf30e23 | 3 years ago |
zack | 2d925ee7af | 3 years ago |
zack | 60609d03e9 | 3 years ago |
zack | e79e8f895e | 3 years ago |
zack | 8cb1a2e82e | 3 years ago |
zack | bf88811291 | 3 years ago |
zack | b2d209136a | 3 years ago |
zack | 5ea33e5068 | 3 years ago |
ju|剧浩宇 | 00aa706b1f | 4 years ago |
zack | 3478bd0ac6 | 4 years ago |
zack | d51e4171ed | 4 years ago |
zack | cbdac5146e | 4 years ago |
pengda | f1600566e0 | 4 years ago |
pengda | 283f40f697 | 4 years ago |
zack | ff97ecf5fd | 4 years ago |
zack | 3f6541199b | 4 years ago |
zack | 0cf74b4e96 | 4 years ago |
zack | 471a43570c | 4 years ago |
zack | bc90de3c16 | 4 years ago |
zack | 128cd31f3c | 4 years ago |
zack | 8ec9a4a4ee | 4 years ago |
zack | cf6488f8cf | 4 years ago |
15 changed files with 377 additions and 200 deletions
@ -0,0 +1,29 @@
|
||||
package com.fr.data; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class SimpleArrayTableDataDemo extends SimpleTableData { |
||||
|
||||
/** |
||||
* 初始化列头 |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public String[] initColumnNames() { |
||||
return new String[]{"Name", "Score"}; |
||||
} |
||||
|
||||
/** |
||||
* 加载行列数据 |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public List<Object[]> loadData() { |
||||
ArrayList<Object[]> valueList = new ArrayList(); |
||||
valueList.add(new Object[]{"Alex", 15}); |
||||
valueList.add(new Object[]{"Helly", 22}); |
||||
valueList.add(new Object[]{"Bobby", 99}); |
||||
return valueList; |
||||
} |
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.fr.data; |
||||
|
||||
import com.fr.file.ConnectionConfig; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.ParameterProvider; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.ResultSet; |
||||
import java.sql.ResultSetMetaData; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 带参数的程序数据集Demo 跟ParamTableDataDemo功能一样,但实现更简单 |
||||
* |
||||
* @author fanruan |
||||
*/ |
||||
public class SimpleParamTableDataDemo extends SimpleTableData { |
||||
|
||||
@Override |
||||
public String[] initColumnNames() { |
||||
String[] columnNames = new String[10]; |
||||
for (int i = 0; i < 10; i++) { |
||||
columnNames[i] = "column#" + i; |
||||
} |
||||
return columnNames; |
||||
} |
||||
|
||||
@Override |
||||
public List<Object[]> loadData() { |
||||
// 保存得到的数据库表名
|
||||
String tableName = ((ParameterProvider) (parameters.get().toArray())[0]).getValue().toString(); |
||||
|
||||
// 构造SQL语句,并打印出来
|
||||
String sql = "select * from " + tableName; |
||||
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql); |
||||
// 保存得到的结果集
|
||||
ArrayList<Object[]> valueList = new ArrayList(); |
||||
// 下面开始建立数据库连接,按照刚才的SQL语句进行查询
|
||||
// 根据连接名获取FR数据连接定义的数据连接,如果没有定义,也可以参考getConnection方法自己创建连接
|
||||
com.fr.data.impl.Connection conn = ConnectionConfig.getInstance().getConnection("FRDemo"); |
||||
Connection con = null; |
||||
try { |
||||
con = conn.createConnection(); |
||||
Statement stmt = con.createStatement(); |
||||
ResultSet rs = stmt.executeQuery(sql); |
||||
// 获得记录的详细信息,然后获得总列数
|
||||
ResultSetMetaData rsmd = rs.getMetaData(); |
||||
int colNum = rsmd.getColumnCount(); |
||||
// 用对象保存数据
|
||||
Object[] objArray = null; |
||||
while (rs.next()) { |
||||
objArray = new Object[colNum]; |
||||
for (int i = 0; i < colNum; i++) { |
||||
objArray[i] = rs.getObject(i + 1); |
||||
} |
||||
// 在valueList中加入这一行数据
|
||||
valueList.add(objArray); |
||||
} |
||||
// 释放数据库资源
|
||||
rs.close(); |
||||
stmt.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} finally { |
||||
try { |
||||
if (con != null) { |
||||
con.close(); |
||||
} |
||||
} catch (SQLException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
return valueList; |
||||
} |
||||
/** |
||||
* 获取数据库连接 driverName和 url 可以换成您需要的 |
||||
* |
||||
* @return Connection |
||||
*/ |
||||
private Connection getConnection() { |
||||
|
||||
String driverName = "org.sqlite.JDBC"; |
||||
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db"; |
||||
String username = ""; |
||||
String password = ""; |
||||
Connection con = null; |
||||
try { |
||||
Class.forName(driverName); |
||||
con = DriverManager.getConnection(url, username, password); |
||||
|
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return con; |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
package com.fr.demo; |
||||
|
||||
import com.fr.data.core.db.DBUtils; |
||||
import com.fr.form.main.Form; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.session.SessionLocalManager; |
||||
import com.fr.web.weblet.DBFormlet; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.io.InputStream; |
||||
import java.sql.Blob; |
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Statement; |
||||
import java.util.Map; |
||||
|
||||
|
||||
|
||||
public class NewReadFrmFromDatabase extends DBFormlet { |
||||
|
||||
@Override |
||||
public Form createForm(HttpServletRequest reportletRequest) { |
||||
String name = reportletRequest.getParameter("reportname"); |
||||
return createForm(name); |
||||
} |
||||
|
||||
@Override |
||||
public Form createForm(String reportName) { |
||||
Form form = new Form(); |
||||
Connection connection = null; |
||||
try { |
||||
connection = getConnection(); |
||||
// 从数据库中读模板
|
||||
String sql = "select frm from report where frmname = '" + reportName |
||||
+ "'"; |
||||
Statement smt = connection.createStatement(); |
||||
ResultSet rs = smt.executeQuery(sql); |
||||
while (rs.next()) { |
||||
Blob blob = rs.getBlob(1); |
||||
FineLoggerFactory.getLogger().info(blob.toString()); |
||||
InputStream ins = blob.getBinaryStream(); |
||||
form.readStream(ins); |
||||
return form; |
||||
} |
||||
} catch (Exception e) { |
||||
throw SessionLocalManager.createLogPackedException(e); |
||||
}finally { |
||||
DBUtils.closeConnection(connection); |
||||
} |
||||
|
||||
return form; |
||||
} |
||||
|
||||
private static Connection getConnection() throws ClassNotFoundException, SQLException { |
||||
// 定义数据连接(根据你实际数据库信息进行修改)
|
||||
String driver = "com.mysql.jdbc.Driver"; |
||||
String url = "jdbc:mysql://localhost:3306/test"; |
||||
String user = "root"; |
||||
String pass = "123456"; |
||||
Class.forName(driver); |
||||
Connection conn = DriverManager.getConnection(url, user, pass); |
||||
return conn; |
||||
} |
||||
|
||||
@Override |
||||
public void setParameterMap(Map<String, Object> arg0) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
} |
@ -1,78 +0,0 @@
|
||||
package com.fr.io; |
||||
|
||||
import com.fr.base.operator.common.CommonOperator; |
||||
import com.fr.chart.activator.ChartBaseActivator; |
||||
import com.fr.cluster.engine.activator.standalone.StandaloneModeActivator; |
||||
import com.fr.config.activator.BaseDBActivator; |
||||
import com.fr.config.activator.ConfigurationActivator; |
||||
import com.fr.env.operator.CommonOperatorImpl; |
||||
import com.fr.general.I18nResource; |
||||
import com.fr.health.activator.ModuleHealActivator; |
||||
import com.fr.module.Module; |
||||
import com.fr.module.tool.ActivatorToolBox; |
||||
import com.fr.report.ReportActivator; |
||||
import com.fr.report.RestrictionActivator; |
||||
import com.fr.report.module.ReportBaseActivator; |
||||
import com.fr.report.write.WriteActivator; |
||||
import com.fr.scheduler.SchedulerActivator; |
||||
import com.fr.store.StateServiceActivator; |
||||
import com.fr.workspace.simple.SimpleWork; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.io.InputStream; |
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.PreparedStatement; |
||||
|
||||
public class SaveReportToDatabase { |
||||
public static void main(String[] args) { |
||||
SaveReport(); |
||||
} |
||||
private static void SaveReport() { |
||||
try { |
||||
// 连接数据库
|
||||
String driver = "com.mysql.jdbc.Driver"; |
||||
String url = "jdbc:mysql://review.finedevelop.com:3306/susie"; |
||||
String user = "root"; |
||||
String pass = "ilovejava"; |
||||
Class.forName(driver); |
||||
Connection conn = DriverManager.getConnection(url, user, pass); |
||||
PreparedStatement presmt = conn |
||||
.prepareStatement("insert into report values(?,?)"); |
||||
// 读进需要保存入库的模板文件
|
||||
// 首先需要定义执行所在的环境,这样才能正确读取数据库信息
|
||||
// 定义报表运行环境,用于执行报表
|
||||
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), |
||||
new ConfigurationActivator(), |
||||
new ResourceRepositoryActivator(), |
||||
new StandaloneModeActivator(), |
||||
new ModuleHealActivator(), |
||||
new StateServiceActivator(), |
||||
new ChartBaseActivator(), |
||||
new SchedulerActivator(), |
||||
new ReportBaseActivator(), |
||||
new RestrictionActivator(), |
||||
new ReportActivator(), |
||||
new WriteActivator()); |
||||
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl()); |
||||
String envpath = "//Applications//FineReport10_325//webapps//webroot//WEB-INF";//工程路径
|
||||
SimpleWork.checkIn(envpath); |
||||
I18nResource.getInstance(); |
||||
module.start(); |
||||
|
||||
File cptfile = new File("//doc//Primary//Parameter//Parameter.cpt"); |
||||
int lens = (int) cptfile.length(); |
||||
InputStream ins = new FileInputStream(cptfile); |
||||
// 将模板保存入库
|
||||
presmt.setString(1, "Parameter.cpt"); // 第一个字段存放模板相对路径
|
||||
presmt.setBinaryStream(2, ins, lens); // 第二个字段存放模板文件的二进制流
|
||||
presmt.execute(); |
||||
conn.commit(); |
||||
presmt.close(); |
||||
conn.close(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue