Getting a ResultSet value from resultset to use throughout jsp

Discussions

Web tier: servlets, JSP, Web frameworks: Getting a ResultSet value from resultset to use throughout jsp

  1. Hi, I create a resultset which has only 1 result(int)
    //CODE
    try
    {
    //Get connection.......
    String sql="SELECT MAX(numberField) from table";
    stmt=con.createStatement();
    rs=stmt.executeQuery(sql);
    while(rs.next())
    {
    int highNum=rs.getInt(1);
    }
    rs.close;
    rs=null;
    stmt.close();
    stmt=null;
    }
    finally
    {
    if(con!=null)
    {con.close();
    }
    }
    this works fine, the problem is I need this value(highNum) throughout the jsp, how?, as now it is only available within the while(rs.next)block.
    THANKS!!
  2. Scope is the problem... you are creating and intializing the int value inside of the brackets of the while loop and it won't be accessible to anything outside of the brackets.

    Try this instead:

    int highNum = 0;
    while(rs.next())
    {
       highNum=rs.getInt(1);
    }

    That'll solve your problem...

    Greg.