From 745b53362c2f87470feb82dc209ca01115c2d4ed Mon Sep 17 00:00:00 2001 From: "Leo.Cai" <1836630213@qq.com> Date: Mon, 14 Oct 2019 09:35:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?http://www.finedevelop.com:2016/browse/DEMO?= =?UTF-8?q?-2670=20=E6=96=B0=E5=A2=9E10.0=E4=BB=8E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=AF=BB=E5=8F=96frm=E5=86=B3=E7=AD=96=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/demo/ReadfrmFromDatabase.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/com/fr/demo/ReadfrmFromDatabase.java diff --git a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java new file mode 100644 index 0000000..799d44e --- /dev/null +++ b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java @@ -0,0 +1,58 @@ +package com.fr.demo; + +import com.fr.io.utils.ResourceIOUtils; +import com.fr.web.weblet.Formlet; +import com.fr.form.main.Form; +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 ReadfrmFromDatabase extends Formlet { + + + public Form createForm(HttpServletRequest reportletRequest) { + + Form form= new Form(); + String name = reportletRequest.getParameter("reportname").toString(); + try { + // 定义数据连接(根据你实际数据库信息进行修改) + 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); + // 从数据库中读模板 + String sql = "select B from report where A = '" + name + + "'"; + Statement smt = conn.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); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(ResourceIOUtils.getRealPath("assets")); + return form; + } + + @Override + public void setParameterMap(Map arg0) { + // TODO Auto-generated method stub + + } + + +} \ No newline at end of file From 397bfa1d663de3c677ffd95a9c867756b698c70a Mon Sep 17 00:00:00 2001 From: "Leo.Cai" <1836630213@qq.com> Date: Mon, 14 Oct 2019 09:52:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?http://www.finedevelop.com:2016/browse/DEMO?= =?UTF-8?q?-2670=20=E6=96=B0=E5=A2=9E10.0=E4=BB=8E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=AF=BB=E5=8F=96frm=E5=86=B3=E7=AD=96=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E7=BC=96=E7=A0=81=E6=A0=BC=E5=BC=8F=E6=94=B9=E4=B8=BA?= =?UTF-8?q?utf-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fr/demo/ReadfrmFromDatabase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java index 799d44e..5180fee 100644 --- a/src/main/java/com/fr/demo/ReadfrmFromDatabase.java +++ b/src/main/java/com/fr/demo/ReadfrmFromDatabase.java @@ -23,14 +23,14 @@ public class ReadfrmFromDatabase extends Formlet { Form form= new Form(); String name = reportletRequest.getParameter("reportname").toString(); try { - // 定义数据连接(根据你实际数据库信息进行修改) + // 瀹氫箟鏁版嵁杩炴帴(鏍规嵁浣犲疄闄呮暟鎹簱淇℃伅杩涜淇敼) 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); - // 从数据库中读模板 + // 浠庢暟鎹簱涓妯℃澘 String sql = "select B from report where A = '" + name + "'"; Statement smt = conn.createStatement();