You can inspect the values of both local variables (declared in a method) and class static variables in the debugger.
You can inspect the values of local variables in a method
as you step through the code, to better understand what is happening.
You must have compiled the class with the javac -g
option
to do this.
Inspecting and modifing the value of a variable
Set a breakpoint at the first line of the JDBCExamples.Query method. This line is as follows:
int max_price = 0
In Interactive SQL, enter the following statement again to execute the method:
SELECT JDBCExamples.Query()
The query executes only as far as the breakpoint.
Press F7 to step to the next line. The max_price variable has now been declared and initialized to zero.
If the Local Variables window is not displayed, choose Window > Local Variables to display it.
The Local Variables window shows that there are several local
variables. The max_price variable has
a value of zero. All others are listed as variable
not in scope
, which means they are not yet
initialized.
In the Local Variables window, double-click the Value column entry for max_price, and type in 45 to change the value of max_price to 45.
The value 45 is larger than any other price. Instead of returning 24, the query will now return 45 as the maximum price.
In the Source window, press F7 repeatedly to step through the code. As you do so, the values of the variables appear in the Local Variables window. Step through until the stmt and result variables have values.
Expand the result object by clicking the icon next to it, or setting the cursor on the line and pressing Enter. This displays the values of the fields in the object.
When you have experimented with inspecting and modifying variables, press F5 to complete the execution of the query and finish the tutorial.
In addition to local variables, you can display class-level variables (static variables) in the debugger Statics window, and inspect their values in the Inspection window. For more information, see the debugger online Help.