当前位置: 代码迷 >> Java Web开发 >> executeUpdate错误
  详细解决方案

executeUpdate错误

热度:1179   发布时间:2013-02-25 21:12:33.0
executeUpdate异常
String new_score = "update learning_paper set lp_votetimes = '"+ newscore + "' where lp_issue='"+issue+"' and lp_part='"+part+"' and lp_title='"+title+"'";
open();
try {
st = dbConn.createStatement();
//PreparedStatement ps = dbConn.prepareStatement(new_score);
//ps.executeUpdate();
st.execute(new_score);
//st.executeUpdate(new_score);
} catch (SQLException e) {
close();
}
new_score 语句在数据库中可以执行,但是写成java语句就没有反应,不报错,估计是tomcat没反应了。各位高手帮我看看,是什么问题?

------解决方案--------------------------------------------------------
new_score 语句在数据库中可以执行,那是你把数据写死了。

你试试在DEBUG下 测试 new_score 是如何生成 SQL 的。
------解决方案--------------------------------------------------------
重启数据库服务,重启TOMCAT试试,可能是类似缓存的问题
------解决方案--------------------------------------------------------
把你的new_score输出到控制的台,然后再复制出来放到数据库中去执行看,能不能出结果。
------解决方案--------------------------------------------------------
探讨
把你的new_score输出到控制的台,然后再复制出来放到数据库中去执行看,能不能出结果。

------解决方案--------------------------------------------------------
你的代码有在sevlet里面掉用吗?既然你用到了tomcat,你肯定是jsp页面提交过来然后条用这些方法的吧

String new_score = "update learning_paper set lp_votetimes = '"+ newscore + "' where lp_issue='"+issue+"' and lp_part='"+part+"' and lp_title='"+title+"'"; 
open(); 
try { 
st = dbConn.createStatement(); 
//PreparedStatement ps = dbConn.prepareStatement(new_score); 
//ps.executeUpdate(); 
st.execute(new_score); 
//st.executeUpdate(new_score); 
} catch (SQLException e) { 
close(); 


1 首先看看你的jsp页面提交到servlet是否成功!,在你的servlet的 post()方法里System.out.print("进入Servlet");

2 看看有没有反应!。如果你的jsp进入了servlet,你的方法说明也成功了,然后检查你的参数从jsp传递过来没有!
例如:System.out.print(request.getParamete("newscore"))

3 在servlet中system.out.print(new_score);检查你的动态生成的sql语句是否语法有误

3 st对象中的executeUpdate();方法返回int的 你可以 System.out.print(st.executeUpdate(new_score)); 检查的修改有没有成功
------解决方案--------------------------------------------------------
探讨
数据库是否存在锁