程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> mysql 數據庫-servlet,mysql 數據已更新,但數據庫裡的數據沒有更新,請問這個是什麼情況?

mysql 數據庫-servlet,mysql 數據已更新,但數據庫裡的數據沒有更新,請問這個是什麼情況?

編輯:編程綜合問答
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);
}

最佳回答:


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved