//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);
}
servlet,mysql 数据已更新,但数据库里的数据没有更新,请问这个是什么情况?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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);
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥200 uniapp长期运行卡死问题解决
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
- ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集