struts构建文件上传(七)

2016-02-19 15:00 5 1 收藏

下面图老师小编要向大家介绍下struts构建文件上传(七),看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - 编程语言 】

  

package tester.business.maitain;
import tclcc.tester.business.maitain.Trainplan;
import tclcc.tester.util.DBConn;
import java.sql.*;
import java.util.*;
public class TrainPlanDAO {
private DBConn dbconn = null;
private Connection conn = null;
private static final String ADD_TRAINPLAN=
"INSERT INTO KS_TRAINPLAN (p_id,p_title,issue_time,issuer,p_content,p_accessory) VALUES (lpad(SEQ_P_ID.nextVal,10,´0´),?,?,to_date(?,´yyyy-mm-dd´),?,?,?)";
private final static String UPDATE_TRAINPLAN=
"UPDATE KS_TRAINPLAN set p_id=?,p_title=?,post_index=?,issue_time=to_date(?,´yyyy-mm-dd´),issuer=?,p_content=?,p_accessory=? where p_id=?";
/**
* get a connection from a DB pool
* @return Connection
*/
public TrainPlanDAO() {
try {
dbconn = new DBConn();
conn = dbconn.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* add a row into DB
* @param examinee Examinee
* @throws SQLException
*/
public void addTrainPlan(Trainplan trainPlan) throws SQLException {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(ADD_TRAINPLAN);
pstmt.setString(1, trainPlan.getP_title());
pstmt.setString(2, trainPlan.getIssue_time());
pstmt.setString(3, trainPlan.getIssuer());
pstmt.setString(4, trainPlan.getP_content());
pstmt.setString(5, trainPlan.getP_accessory());
pstmt.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
pstmt.close();
//conn.close();
} catch (SQLException ex1) {
}
}
}
/**
* remove a row from DB
* @param trainPlan TrainPlan
* @throws SQLException
*/
public void removeTrainPlan(Trainplan trainPlan) throws SQLException {
this.removeTrainPlan(trainPlan.getP_id());
}
/**
* remove a row from DB
* @param p_id int
* @throws SQLException
*/
public void removeTrainPlan(int p_id) throws SQLException {
Statement stmt = null;
try {
stmt = conn.createStatement();
stmt.execute("DELETE FROM ks_trainplan WHERE p_id=" + p_id);
} catch (SQLException ex) {
ex.printStackTrace();
throw new SQLException("SQLExction on : TrainPlanDAO.removeExaminee()");
} finally {
try {
conn.close();
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
/**
* update a row
* @param examinee Examinee
* @throws SQLException
*/
public void updateTrainPlan(Trainplan trainPlan) throws SQLException {
PreparedStatement pstmt = null;
try {
// UPDATE_TRAINPLAN = UPDATE_TRAINPLAN + "where p_id =" + trainPlan.getP_id(); //the condition need modification
pstmt = conn.prepareStatement(UPDATE_TRAINPLAN);
pstmt.setInt(1, trainPlan.getP_id());
pstmt.setString(2, trainPlan.getP_title());
pstmt.setInt(3, trainPlan.getPost_index());
pstmt.setString(4, trainPlan.getIssue_time());
pstmt.setString(5, trainPlan.getIssuer());
pstmt.setString(6, trainPlan.getP_content());
pstmt.setString(7, trainPlan.getP_accessory());
pstmt.setInt(8,trainPlan.getP_id());
pstmt.executeUpdate();
} /*catch (SQLException ex) {
ex.getStackTrace();
throw new SQLException("SQLExction on : TrainPlanDAO.updateExaminee()");
} */
catch(SQLException sqle){
do
{
System.err.println("Exception occoured:nMessage:"+sqle.getMessage());
System.err.println("SQL state:"+sqle.getSQLState());
System.err.println("Vendor code:"+sqle.getErrorCode()+"n---------------");
} while((sqle=sqle.getNextException())!=null);
}finally {
try {
conn.close();
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
}
/**
* get all record from DB
* @throws SQLException
* @return Collection
*/
public Collection getAll() throws SQLException {
Statement stmt = null;
ResultSet rs = null;
Trainplan trainPlan = null;
Collection list = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM ks_trainplan");
list = new ArrayList();
while (rs.next()) {
trainPlan = new Trainplan();
trainPlan.setP_id(rs.getInt("P_ID"));
trainPlan.setP_title(rs.getString("P_TITLE"));
trainPlan.setPost_index(rs.getInt("POST_INDEX"));
trainPlan.setIssue_time(rs.getString("ISSUE_TIME"));
trainPlan.setIssuer(rs.getString("ISSUER"));
trainPlan.setP_content(rs.getString("P_CONTENT"));
trainPlan.setP_accessory(rs.getString("P_ACCESSORY"));
list.add(trainPlan);
}
} catch (SQLException ex) {
} finally {
try {
conn.close();
} catch (SQLException ex1) {
ex1.printStackTrace();
}
return list;
}
}
public static String toString(Trainplan trainPlan){
return trainPlan.getP_title();
}
/**
* for test
* @param args String[]
*/
}

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

来源:http://www.tulaoshi.com/n/20160219/1608587.html

延伸阅读
Model就是在对用户请求的整个控制过程中,真正处理用户请求并保存处理结果的对象,在整个过程中,我们一般利用JavaBean来把一些信息保存起来以便在各个对象之间传递。因为在框架中,Model对象是真处理商业逻辑功能的对象,因此也就是框架中应用需求实现相关性最大的的部分。在Struts的实现里,Model的具体表现形式就是ActionForm对象和与其...
在upload.jsp页面中将多个文件域对象命名为相同的名字,这样在action中就可以将多个文件域解析成一个数组,数组的大小就是文件域的个数,同时一个文件域解析成三个对应的变量,因此多个文件域对应三个数组,其中每个数组的大小就是文件域的个数。jsp页面代码如下: 代码如下: form action="upload.action" name="uploadForm" method="post" e...
标签: Web开发
使用示例: upload.php ?php include_once "upload.class.php"; if ($Submit != '') {     $fileArr['file'] = $file;     $fileArr['name'] = $file_name;     $fileArr['size'] = $file_size;     $fileArr['type'] = $file_type;    &nbs...
标签: 软件教程
flashfxp是一款很常用的FTP管理工具,也是相对而言比较简单的管理工具。下面小编就为大家介绍一下flashfxp怎么上传文件,希望能帮到大家 1、首先,打开FlashFXP软件 2、点击“站点”按钮,将网站添加到新的站点 3、站点添加好后,添加“连接”图标按钮或者双击flashifxp sites下的用户,连接网站。确认网...
一、访问或添加request/session/application属性 public String scope() throws Exception{    ActionContext ctx = ActionContext.getContext();    ctx.getApplication().put("app", "应用范围");//往ServletContext里放入app    ctx.getSession().put("ses", "session范围");//往session里放入ses  &...

经验教程

665

收藏

96
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部