Compare commits
14 Commits
release/10
...
persist/10
Author | SHA1 | Date |
---|---|---|
|
c21ebed9f4 | 4 years ago |
|
ce7482718d | 4 years ago |
|
26e083a658 | 4 years ago |
|
d1776fa526 | 5 years ago |
|
ca629a1ff6 | 5 years ago |
|
99ff96fea6 | 5 years ago |
|
e1f402023f | 5 years ago |
|
5a3d9301af | 5 years ago |
|
34ec362f64 | 5 years ago |
|
c81c49f7ad | 5 years ago |
|
9a474478b3 | 5 years ago |
|
10e88848e4 | 5 years ago |
|
d6274eea84 | 6 years ago |
|
de51123131 | 6 years ago |
15 changed files with 200 additions and 377 deletions
@ -1,29 +0,0 @@ |
|||||||
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; |
|
||||||
} |
|
||||||
} |
|
@ -1,100 +0,0 @@ |
|||||||
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; |
|
||||||
} |
|
||||||
} |
|
@ -1,72 +0,0 @@ |
|||||||
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
|
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,78 @@ |
|||||||
|
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