Inspecting local variables

You can inspect the values of local variables in a method as you step through the code, to better understand what is happening.

To inspect and change the value of a variable:

  1. Set a breakpoint at the first line of the selecter( ) method from the Breakpoint window. This line is:

    String sql = "select name, home from xmp where
    			id=?";
    
  2. In Interactive SQL, enter the following statement again to execute the method:

    select JDBCExamples.serverMain(‘select’)
    

    The query executes only as far as the breakpoint.

  3. Press F7 to step to the next line. The sql variable has now been declared and initialized.

  4. From the Source window, select Window→Locals. The Local window appears.

    The Locals window shows that there are several local variables. The sql variable has a value of zero. All others are listed as not in scope, which means they are not yet initialized.

    You must add the variables to the list in the Inspect window.

  5. In the Source window, press F7 repeatedly to step through the code. As you do so, the values of the variables appear in the Locals window.

    If a local variable is not a simple integer or other quantity, then as soon as it is set a + sign appears next to it. This means the local variable has fields that have values. You can expand a local variable by double-clicking the + sign or setting the cursor on the line and pressing Enter.

  6. Complete the execution of the query to finish this exercise.