Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #364
| From | "Donkey Hottie" <donkey.hottie@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: How to output record |
| Message-ID | <Xns9B5ADFD4F3274SH15SGybs1ysmajw54s5@194.100.2.89> (permalink) |
| Newsgroups | comp.lang.java.databases |
| References | <4922dc21$0$10534$db0fefd9@news.zen.co.uk> |
| Date | 2011-04-27 15:23 +0000 |
| Organization | TDS.net |
To: comp.lang.java.databases
RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote in news:4922dc21$0
$10534$db0fefd9@news.zen.co.uk:
>
> List<Nationality> qresult = ...getResultList();
> for (Nationality nationality: qresult) {
> String id = nationality.getID();
> String name = nationality.getName();
> ...
> }
>
> I've not seen an example using generics so you probably have to perform
> a cast yourself.
>
> List qresult = ...getResultList();
> for (Object record: qresult) {
> Nationality nationality = (Nationality) record;
> String id = nationality.getID();
> String name = nationality.getName();
> ...
> }
>
The first example with generics work fine, at least for me.
Query q = em.createNamedQuery(oNationality.getAllo) ;
List<Nationality> nationalities = q.getResultList();
for (Nationality nationality : nationalities)
{
System.out.println("Id: " + nationality.getId());
System.out.println("Name: " + nationality.getName());
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.databases | Previous | Next — Previous in thread | Find similar
How to output record data "Ameen" <ameen@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: How to output record "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: How to output record "Donkey Hottie" <donkey.hottie@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
csiph-web