2 u010472048 u010472048 于 2013.10.25 18:32 提问

servlet,mysql 数据已更新,但数据库里的数据没有更新,请问这个是什么情况?

//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);
}

1个回答

qfvszy
qfvszy   2013.10.30 18:05
已采纳

没有提交
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);
}

u010472048
u010472048 确实提交了呀...
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片