JDBC的问题

public boolean regis(UserForm uf) throws SQLException{
boolean flag=false;
Connection conn=null;
PreparedStatement pst=null;
int index=1;
int executeup=-1;
try {
conn=getconn();
pst=conn.prepareStatement(REGIS);
pst.setString(index++, uf.getNAME());
pst.setString(index++, uf.getPWD());
pst.setString(index++, uf.getTEL());
pst.setString(index++, uf.getDZ());
pst.setString(index++, uf.getDEP());
executeup=pst.executeUpdate();//如果我有一个字段位超出范围,执行executeUpdate()不会返回受影响行数,应该继续执行下面语句,返回false,但是它超出范围,程序就不往下执行了只执行到executeup=pst.executeUpdate();这个位置
} catch (SQLException e) {
throw e;
}finally{
DBConnection.closePreparedStatement(pst);
DBConnection.closeConnection(conn);
}
if(executeup>0){
flag=true;
}
return flag;
}





executeup=pst.executeUpdate();//如果我有一个字段位超出范围,执行executeUpdate()不会返回受影响行数,应该继续执行下面语句,返回false,但是它超出范围,程序就不往下执行了只执行到executeup=pst.executeUpdate();这个位置

作者: quanlei1507053   发布时间: 2011-06-07

超出范围:
数据库3位,更新成4位吗?

应该到catch里面了吧!

作者: yashucn   发布时间: 2011-06-07

发生了异常肯定是被catch捕获到,但你的catch里面又抛出了这个异常,就会使下面的程序不再继续执行
可以改为
catch (SQLException e) {
e.printStackTrace();//或者System.out.println(e.getMessage());
}
这样发生错误的时候就还会继续执行下面的程序,最终返回false

作者: zxingchao2009   发布时间: 2011-06-07

catch (SQLException e) {
throw e;
}

try -> catch -> throw ->catch ->throw ->...

作者: lrbyantai   发布时间: 2011-06-07