A really simple question about resultSets.

A really simple question about resultSets.

Post by Simon Harve » Wed, 14 Aug 2002 20:19:31



Aplogies if you just had the misfortune of reading my first post just a
second ago!! I have a similar related problem but I thought it might be
useful to seperate the two questions so I hope you dont mind.

I'm a bit confused about how to get info out of a resultSet successfully.
The info in my database is all fairly simple stuff like a few strings, a
couple of ints, and maybe a date. Now it seems to me that it would be quite
difficult to write code that would know what sort of data it was about to
received with results.getXXX statement, so how do you just grab simple no
matter what it is? Is it possible for resultSet.getString(columnNumber) to
just get whatever the target column type is. Does this work and give a fair
interpretation of what was in the column?

I would test this myself but my code is a bit of a mess, and I'm a bit
confused as to whats going on. If someone could just clear that question up,
that would clear a big grey area in my head so that I can eliminate that
posibility.

Many thanks guys.

Take Care

Simon

 
 
 

A really simple question about resultSets.

Post by Bob Barne » Thu, 15 Aug 2002 02:33:50



Quote:> I'm a bit confused about how to get info out of a resultSet
> successfully. The info in my database is all fairly simple stuff like
> a few strings, a couple of ints, and maybe a date. Now it seems to me
> that it would be quite difficult to write code that would know what
> sort of data it was about to received with results.getXXX statement,
> so how do you just grab simple no matter what it is? Is it possible
> for resultSet.getString(columnNumber) to just get whatever the target
> column type is. Does this work and give a fair interpretation of what
> was in the column?

  You can use resultSet.getString(columnNumber) for any data type. If
all you're doing is displaying the column data that should suffice. If
you're intending something more complicated, like populating another
database, you can use ResultSetMetaData to retrieve data type
information.
Quote:> Many thanks guys.

> Take Care

> Simon


 
 
 

A really simple question about resultSets.

Post by Jason Simpso » Fri, 16 Aug 2002 04:51:11


On Tue, 13 Aug 2002 at 12:19, Simon Harvey so generously added:

Quote:> I'm a bit confused about how to get info out of a resultSet successfully.
> The info in my database is all fairly simple stuff like a few strings, a
> couple of ints, and maybe a date. Now it seems to me that it would be quite
> difficult to write code that would know what sort of data it was about to
> received with results.getXXX statement,

Well, you write the query, so you obviously know what table you are
querying against and what the types of the columns are, I would hope.
Otherwise, how would you write your query in the first place???

Quote:> so how do you just grab simple no
> matter what it is? Is it possible for resultSet.getString(columnNumber) to
> just get whatever the target column type is. Does this work and give a fair
> interpretation of what was in the column?

You can use ResultSet.getObject() and it will return an Object of the
correct type. Of course, then you get to use instanceof to determine the
type when you shoudl already know it. You could also use ResultSetMetaData
to determine the types of the columns, but again, you should probably know
them at the time you write your query.

--
Jason Simpson

"I love deadlines - I like the whooshing sound they make as they fly  by."
-- Douglas Adams

 
 
 

1. A simple question, really simple

How can I make a case sensitive comparsion in the WHERE clause? I
can't found the answer from the on-line help.



----------------------------------------------------------------------------
           Personal homepage : http://www.hk.super.net/~leolau

2. Decoding

3. Really Simple VFP Question (But Not For Me)

4. Help with dBaseIV Record Deleting

5. Really simple PL-SQL cursor question...

6. A2K and Read-only SP

7. Really simple question

8. NextRecordset

9. Really simple SQL Question

10. Really simple DB Question

11. A really simple jdbc question - please, please help

12. Really simple DB question...

13. Really simple script question (I think)