Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to inspect java resultset values
How to inspect java resultset values [message #204075] Mon, 09 April 2007 14:45 Go to next message
Eclipse UserFriend
Originally posted by: ns_dkerber.ns_WarrenRogersAssociates.com

I'm having trouble getting the correct values out of my resultset
getDouble() statement. When I execute the statement in my SQL tool, I
get the numbers I expect, but in my java program, I'm getting 0. The
other fields are returning correct values.

How can I inspect the values returned in the resultset? When I have the
variables window open, I can see the resultset, and it shows the number
of rows and colums, the columns, etc, but I can't seem to find the
Values of the fields. How can I find them?

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Re: How to inspect java resultset values [message #204118 is a reply to message #204075] Mon, 09 April 2007 19:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: irbull.cs.uvic.ca

The results view shows you all the variables that are currently in
scope. If you have stepped out of the method (or block) and the
variables are no longer in scope they will not appear. All field
(instance variables on the object itself) appear under the "this" parent
in the tree.

cheers,
ian

David Kerber wrote:
> I'm having trouble getting the correct values out of my resultset
> getDouble() statement. When I execute the statement in my SQL tool, I
> get the numbers I expect, but in my java program, I'm getting 0. The
> other fields are returning correct values.
>
> How can I inspect the values returned in the resultset? When I have the
> variables window open, I can see the resultset, and it shows the number
> of rows and colums, the columns, etc, but I can't seem to find the
> Values of the fields. How can I find them?
>
Re: How to inspect java resultset values [message #204150 is a reply to message #204118] Mon, 09 April 2007 20:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ns_dkerber.ns_WarrenRogersAssociates.com

In article <eve3lk$5ev$1@build.eclipse.org>, irbull@cs.uvic.ca says...
> The results view shows you all the variables that are currently in
> scope. If you have stepped out of the method (or block) and the
> variables are no longer in scope they will not appear. All field
> (instance variables on the object itself) appear under the "this" parent
> in the tree.

Thanks for the response, but I'm not looking for object fields, but
rather the fields returned by my sql query in a resultset object, which
is declared at the beginning of the method I'm currently in:

ResultSet rs

and then later on:

rs = statement.executeQuery( sql )

This executes fine, and most of the returned data is correct, but I'm
having trouble getting the correct value for one specific field. I can
see the field names ok, but not their values. That's what I'm trying to
figure out.

.....

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Re: How to inspect java resultset values [message #204165 is a reply to message #204150] Tue, 10 April 2007 05:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: irbull.cs.uvic.ca

> Thanks for the response, but I'm not looking for object fields, but
> rather the fields returned by my sql query in a resultset object, which
> is declared at the beginning of the method I'm currently in:
>
> ResultSet rs
>
> and then later on:
>
> rs = statement.executeQuery( sql )
>
> This executes fine, and most of the returned data is correct, but I'm
> having trouble getting the correct value for one specific field. I can
> see the field names ok, but not their values. That's what I'm trying to
> figure out.
I don't know much about the SQL API, but this sounds more like a
debugging problem than an SQL one.

What is shown in the value column adjacent to field you are interested
in? I just took a look at the variable view, and every field has a
value (it may be null, or 0, but it has a value). Is it just blank?

What happens if you print out the value?
System.out.println( rs.theFieldYouAreInterestedIn);

Just looking at your original question again, it looks like you are
calling a method on the result set. Can you step into getDouble()?

cheers,
ian


>
> ....
>
Re: How to inspect java resultset values [message #204265 is a reply to message #204150] Tue, 10 April 2007 22:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse5.rizzoweb.com

David Kerber wrote:
> In article <eve3lk$5ev$1@build.eclipse.org>, irbull@cs.uvic.ca says...
>> The results view shows you all the variables that are currently in
>> scope. If you have stepped out of the method (or block) and the
>> variables are no longer in scope they will not appear. All field
>> (instance variables on the object itself) appear under the "this" parent
>> in the tree.
>
> Thanks for the response, but I'm not looking for object fields, but
> rather the fields returned by my sql query in a resultset object, which
> is declared at the beginning of the method I'm currently in:
>
> ResultSet rs
>
> and then later on:
>
> rs = statement.executeQuery( sql )
>
> This executes fine, and most of the returned data is correct, but I'm
> having trouble getting the correct value for one specific field. I can
> see the field names ok, but not their values. That's what I'm trying to
> figure out.

Because JDBC is pure API (only interfaces, no implementation), the
answer to your question is going to depend on the JDBC driver you are
using. Chances are, it is not well-known how that particular driver
implements storing the data for a ResultSet. As long as it returns the
correct answer to the API methods, the way it stores things internally
is proprietary.
I've tried debugging JDBC drivers before and it has seldom ended well -
usually with large amounts of my hair on the floor and a trip to the
confessional for massive amounts of cursing.

Sorry,
Eric
Re: How to inspect java resultset values [message #204301 is a reply to message #204265] Wed, 11 April 2007 02:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dtoland.email.uophx.edu

It is true that the exact set of methods is dependent on what JDBC implementation
you are using, i.e. the mapping to a specific database engine's datatypes varies,
some methods are pretty generic. Most of the time, you will use methods of
the ResultSet like getInt, getDouble, getString, and getTimestamp. Most of these take either
an integer argument (the index of the column to fetch) or a String argument (the name
of the column in the result set), and return the data type implied by the method's name.

Of course, the column type has to be compatible with the target data type, or a SqlException
will be thrown.

For example, if your query returns columns named "id" and "name" as the first two columns,
you can fetch the name from each row by either:

String name = rs.getString(2);
or
String name = rs.getString("name");

Note that ResultSet columns are 1-based, not 0-based.

When the ResultSet is first returned, it points to nothing. To access each row in turn, you
use rs.next(), which returns true if there is a row to fetch:

while (rs,next())
{
String name = rs.getString("name");
// more processing
}

I hope this helps.

--
Dave Toland
dave.toland@verizon.net

"Eric Rizzo" <eclipse5@rizzoweb.com> wrote in message news:evh1ko$ale$1@build.eclipse.org...
| David Kerber wrote:
| > In article <eve3lk$5ev$1@build.eclipse.org>, irbull@cs.uvic.ca says...
| >> The results view shows you all the variables that are currently in
| >> scope. If you have stepped out of the method (or block) and the
| >> variables are no longer in scope they will not appear. All field
| >> (instance variables on the object itself) appear under the "this" parent
| >> in the tree.
| >
| > Thanks for the response, but I'm not looking for object fields, but
| > rather the fields returned by my sql query in a resultset object, which
| > is declared at the beginning of the method I'm currently in:
| >
| > ResultSet rs
| >
| > and then later on:
| >
| > rs = statement.executeQuery( sql )
| >
| > This executes fine, and most of the returned data is correct, but I'm
| > having trouble getting the correct value for one specific field. I can
| > see the field names ok, but not their values. That's what I'm trying to
| > figure out.
|
| Because JDBC is pure API (only interfaces, no implementation), the
| answer to your question is going to depend on the JDBC driver you are
| using. Chances are, it is not well-known how that particular driver
| implements storing the data for a ResultSet. As long as it returns the
| correct answer to the API methods, the way it stores things internally
| is proprietary.
| I've tried debugging JDBC drivers before and it has seldom ended well -
| usually with large amounts of my hair on the floor and a trip to the
| confessional for massive amounts of cursing.
|
| Sorry,
| Eric
Re: How to inspect java resultset values [message #204331 is a reply to message #204301] Wed, 11 April 2007 11:59 Go to previous message
Eclipse UserFriend
Originally posted by: ns_dkerber.ns_WarrenRogersAssociates.com

Yes, I know how to retrieve values; I've been doing it for months. As I
said in my original post, the problem is that executing a .getDouble()
method on one particular resultset column is returning 0, and when I
copy/paste the sql statement into my sql utility, I get a non-zero
number for that column, and I can't figure out why. The rest of the
columns in that same resultset are fine. That's why I was hoping to be
able to Inspect the values of the sql columns in the variables window,
so I could try to isolate whether the trouble was in the jdbc driver, or
somewhere else in my code.

I ended up coming up with a workaround to get the values for that column
in a different way, but I'd still like to be able to inspect resultset
returned values for future debugging needs, if it can be done.

Thanks for the comments, guys!
Dave


In article <evhid4$77t$1@build.eclipse.org>, dtoland@email.uophx.edu
says...
> It is true that the exact set of methods is dependent on what JDBC implementation
> you are using, i.e. the mapping to a specific database engine's datatypes varies,
> some methods are pretty generic. Most of the time, you will use methods of
> the ResultSet like getInt, getDouble, getString, and getTimestamp. Most of these take either
> an integer argument (the index of the column to fetch) or a String argument (the name
> of the column in the result set), and return the data type implied by the method's name.
>
> Of course, the column type has to be compatible with the target data type, or a SqlException
> will be thrown.
>
> For example, if your query returns columns named "id" and "name" as the first two columns,
> you can fetch the name from each row by either:
>
> String name = rs.getString(2);
> or
> String name = rs.getString("name");
>
> Note that ResultSet columns are 1-based, not 0-based.
>
> When the ResultSet is first returned, it points to nothing. To access each row in turn, you
> use rs.next(), which returns true if there is a row to fetch:
>
> while (rs,next())
> {
> String name = rs.getString("name");
> // more processing
> }
>
> I hope this helps.
>
>

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Previous Topic:adding a view in project explorer
Next Topic:Regarding Command Line arguments
Goto Forum:
  


Current Time: Wed Sep 18 18:18:44 GMT 2024

Powered by FUDForum. Page generated in 0.07768 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top