forked from demo/example
Browse Source
Merge in PG/plugin-report-doc-demo from release/10.0 to persist/10.0 * commit 'd51e4171edd2c1b536ad0149e34a2e41401eb6ab': 无JIRA任务 本地编译发现这个文档插件里面的类编译不通过了,纠正下,这个类在文档里没有用到,无需测试 REPORT-50982 保存模板至数据库后,读取带参数面板的报表会报错空指针,不带参数面板报表可以读取成功 REPORT-50963 优化程序数据集上层设计(abstracttabledata) rt REPORT-50963 新demo里面获取连接的逻辑跟老demo一致 补一下简单程序数据集demo REPORT-50963 优化程序数据集上层设计(abstracttabledata),提交新demopersist/10.0
Icey.Zhang
4 years ago
6 changed files with 222 additions and 11 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,70 @@
|
||||
package com.fr.demo; |
||||
|
||||
import com.fr.data.core.db.DBUtils; |
||||
import com.fr.web.weblet.DBFormlet; |
||||
import com.fr.form.main.Form; |
||||
import java.sql.SQLException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.io.InputStream; |
||||
import java.sql.Blob; |
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.ResultSet; |
||||
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) { |
||||
e.printStackTrace(); |
||||
}finally { |
||||
DBUtils.closeConnection(connection); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
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
|
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue