From 283f40f697b4ad0e5d7fe033910407d8d812c39a Mon Sep 17 00:00:00 2001 From: pengda Date: Thu, 29 Apr 2021 15:57:09 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-50982=20=E4=BF=9D=E5=AD=98=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=87=B3=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=B8=A6=E5=8F=82=E6=95=B0=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E8=A1=A8=E4=BC=9A=E6=8A=A5=E9=94=99=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=EF=BC=8C=E4=B8=8D=E5=B8=A6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=8A=A5=E8=A1=A8=E5=8F=AF=E4=BB=A5=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/demo/NewReadFrmFromDatabase.java | 70 +++++++++++++++++++ .../java/com/fr/demo/ReadfrmFromDatabase.java | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/fr/demo/NewReadFrmFromDatabase.java diff --git a/src/main/java/com/fr/demo/NewReadFrmFromDatabase.java b/src/main/java/com/fr/demo/NewReadFrmFromDatabase.java new file mode 100644 index 0000000..8186fe9 --- /dev/null +++ b/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 arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java index 5180fee..601fca0 100644 --- a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java +++ b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java @@ -31,7 +31,7 @@ public class ReadfrmFromDatabase extends Formlet { Class.forName(driver); 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(); ResultSet rs = smt.executeQuery(sql);