//update新聞
public void update(News news) throws Exception{
DBConnection dbc = new DBConnection();
sql = "UPDATE e_news SET title=?,content=?,type1=?,type2=?,newstype=?,url=?,uploadurl=? WHERE id=?";
try {
pstm = dbc.getConnection().prepareStatement(sql);
pstm.setString(1, news.getTitle());
pstm.setString(2, news.getContent());
pstm.setInt(3, news.getType1());
pstm.setInt(4, news.getType2());
pstm.setInt(5, news.getNewstype());
if (news.getNewstype() != 0) {
news.setUrl(this.subString(news.getContent()));
}
pstm.setString(6, news.getUrl());
pstm.setString(7, news.getUploadurl());
pstm.setInt(8, news.getId());
pstm.executeUpdate();
pstm.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("+++++++++++++++++++++3"+news.getTitle());
System.out.println("+++++++++++++++++++++3"+news.getContent());
System.out.println("+++++++++++++++++++++3"+news.getNewstype());
System.out.println("+++++++++++++++++++++3"+sql);
}
沒有提交
public void update(News news) throws Exception{
DBConnection dbc = new DBConnection();
sql = "UPDATE e_news SET title=?,content=?,type1=?,type2=?,newstype=?,url=?,uploadurl=? WHERE id=?";
try {
Connnection conn = dbc.getConnection();
pstm = conn.prepareStatement(sql);
pstm.setString(1, news.getTitle());
pstm.setString(2, news.getContent());
pstm.setInt(3, news.getType1());
pstm.setInt(4, news.getType2());
pstm.setInt(5, news.getNewstype());
if (news.getNewstype() != 0) {
news.setUrl(this.subString(news.getContent()));
}
pstm.setString(6, news.getUrl());
pstm.setString(7, news.getUploadurl());
pstm.setInt(8, news.getId());
pstm.executeUpdate();
pstm.close();
conn.commit();
} catch (Exception e) {
conn.rollback();
e.printStackTrace();
}
System.out.println("+++++++++++++++++++++3"+news.getTitle());
System.out.println("+++++++++++++++++++++3"+news.getContent());
System.out.println("+++++++++++++++++++++3"+news.getNewstype());
System.out.println("+++++++++++++++++++++3"+sql);
}