- Java code
//执行删除操作 public int delete(member m) { int ret = 0; try{ String sql = "delect from tb_member where ID=" + m.getID(); ret=conn.executeUpdate(sql); //这句没执行 没调用executeUpdate() ???System.out.println("ret="+ret); } catch(Exception e) { ret=0; } conn.close(); return ret; }
打印出来ret是为‘0’难道我没调用executeUpdate()吗?
- Java code
public int executeUpdate(String sql) { int result = 0; try { conn = getConnection(); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); result = stmt.executeUpdate(sql); } catch (SQLException ex) { result = 0; } try { stmt.close(); } catch (SQLException ex1) { } return result; }
------解决方案--------------------
你的Java代码发到JS板块里啊?
JAVA代码的数据库连接语句不全
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
} catch(Exception e) {
ret=0;
}
2、3楼的兄弟已经准确定位错误了,我忍不住吐槽一句:写这种代码的兄弟应该被狂打屁股,就算你确实不希望将异常抛给上一层,但好歹你要让上一层知道你是正常执行还是非正常执行。
} catch(Exception e) {
e.printStackTrace();
ret = -1;
}