forked from demo/example
Browse Source
* commit '397bfa1d663de3c677ffd95a9c867756b698c70a': http://www.finedevelop.com:2016/browse/DEMO-2670 新增10.0从数据读取frm决策报表,编码格式改为utf-8 http://www.finedevelop.com:2016/browse/DEMO-2670 新增10.0从数据库读取frm决策报表release/10.0
Leo.Tsai
5 years ago
1 changed files with 58 additions and 0 deletions
@ -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<String, Object> arg0) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue