点点人久央
2013-10-25 10:32
采纳率: 100%
浏览 2.7k

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 2013-10-30 10: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);
    }

    点赞 打赏 评论

相关推荐 更多相似问题