<%!
public static void UpOnStop(Connection dbConn,String lotType){//19:50--20:00之间停购
String up_sql="update DG_currqc set status='0' where type='" + lotType + "' and status='1'";
PreparedStatement stmt = dbConn.prepareStatement(up_sql);
stmt.executeUpdate();
stmt.close();
}
%>我在jsp页面里申明的dbconn想传到函数里去执行数据库操作
可是却报Unhandled exception type SQLException异常
而如果我把函数内的内容直接写在申明dbconn的下面则会成功执行为什么放在函数里就不行了呢 ???

解决方案 »

  1.   

    补充:
    dbConn的声明如下
    Connection dbConn = DBConnectionPool.getInstance().getConnection();
      

  2.   

    可能是这个dbConn在传递的过程中会有断开连接的可能吧,所以需要抛异常,仅仅是猜测~~
      

  3.   

    因为Connection中有try和catch,涉及数据库的操作都会抛异常,基本常识啊
      

  4.   

    PreparedStatement类对象需要抛出异常。
    <%! 
    public static void UpOnStop(Connection dbConn,String lotType){//19:50--20:00之间停购 
    String up_sql="update DG_currqc set status='0' where type='" + lotType + "' and status='1'"; 
    try{
    PreparedStatement stmt = dbConn.prepareStatement(up_sql); 
    stmt.executeUpdate(); 
    }catch(SQLException ex){ex.printStackTrace();}
    finally{
    stmt.close(); 
    dbcon.close()
    }

    %> 
    楼主试了看看!