forked from demo/example
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