日期:2014-05-18  浏览次数:20595 次

数据库表里字段怎么也更新不了
我需要通过调用我自己写的更新函数来更新数据库的一个字段,怎么也更新不了,我把参数写死了,也更新不了,可是单独在PL/SQl   Developer   里执行那个sql语句就行.   下面是代码,请指教!谢谢!
public   void   modifyDocumentContent(long   docid,   String   item_name,String   item_value,Connection   conn)   {
System.out.println( "coming========== "+docid+ "$   $ "+item_name+ "$     $ "+ "$     $ "+item_value);
String   sql   =   "update   mocha_fe_document_content   set   item_value= '2007-03-19 '   where   document_id=7394   and   item_name= 'daimakudongjie ' ";
PreparedStatement   ps   =   null;
try   {
ps   =   conn.prepareStatement(sql);
// ps.setString(1,   "2007-04-30 ");
// ps.setLong(2,   c);
// ps.setString(3,   "daimakudongjie ");
int   b   =   ps.executeUpdate();
System.out.println( "bbbbb:                 "+b);
System.out.println( "executed==============================!! ");
}   catch   (SQLException   e)   {
e.printStackTrace();
logger.error( "DocumentManager:Error--------- "   +   e.getMessage());
}   finally   {
try   {
if(ps!=null){
ps.close();
}
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
}
}


------解决方案--------------------
更新语句 是得提交的

有个commit()方法..


写在
ps = conn.prepareStatement(sql);
// ps.setString(1, "2007-04-30 ");
// ps.setLong(2, c);
// ps.setString(3, "daimakudongjie ");
int b = ps.executeUpdate();
conn.commit()


后面.

------解决方案--------------------
数据库里面记录没有更新,报异常了吗?
如果正常执行了数据库里面没有有满足条件更新条件的记录
------解决方案--------------------
加System.out.print( "***** ")看看程序执行到哪里。再找找原因。