Browse Source
Merge in PG/plugin-report-doc-demo from ~PENGDA/plugin-report-doc-demo:release/10.0 to release/10.0 * commit '283f40f697b4ad0e5d7fe033910407d8d812c39a': REPORT-50982 保存模板至数据库后,读取带参数面板的报表会报错空指针,不带参数面板报表可以读取成功pull/6/head
pengda
4 years ago
2 changed files with 71 additions and 1 deletions
@ -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