Browse Source

Pull request #50: REPORT-50982 保存模板至数据库后,读取带参数面板的报表会报错空指针,不带参数面板报表可以读取成功

Merge in PG/plugin-report-doc-demo from ~PENGDA/plugin-report-doc-demo:release/10.0 to release/10.0

* commit '283f40f697b4ad0e5d7fe033910407d8d812c39a':
  REPORT-50982 保存模板至数据库后,读取带参数面板的报表会报错空指针,不带参数面板报表可以读取成功
release/10.0
pengda 4 years ago
parent
commit
f1600566e0
  1. 70
      src/main/java/com/fr/demo/NewReadFrmFromDatabase.java
  2. 2
      src/main/java/com/fr/demo/ReadfrmFromDatabase.java

70
src/main/java/com/fr/demo/NewReadFrmFromDatabase.java

@ -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
}
}

2
src/main/java/com/fr/demo/ReadfrmFromDatabase.java

@ -31,7 +31,7 @@ public class ReadfrmFromDatabase extends Formlet {
Class.forName(driver); Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, pass); Connection conn = DriverManager.getConnection(url, user, pass);
// 从数据库中读模板 // 从数据库中读模板
String sql = "select B from report where A = '" + name String sql = "select frm from report where frmname = '" + name
+ "'"; + "'";
Statement smt = conn.createStatement(); Statement smt = conn.createStatement();
ResultSet rs = smt.executeQuery(sql); ResultSet rs = smt.executeQuery(sql);

Loading…
Cancel
Save