• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Some question about Java Progarmming

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have some question about Java Progarmming
I attened the DB ERdigram.
The situation is that there are 4 tables which are company , address, contact and location.
A company may contain many address so thier relationship in 1 to many and 1 address may contain many contact so their relationship is also 1 to many and 1 address only contain 1 location so their relationship is 1 t o1.
I want to select all data from these 4 tables by the company Id.
So First I do the first quesry, I select the data from company table join with address table by the company Id.
Aftrer that I want to do the second query to select the data from contact and location table.
Then the problem come out.
How can I get the FK of contact and location from first query in order to do the second query?
I use JDBCTemplate API in my java code
JDBCTemplate only return a object or a arraylist. But I want to have Object Arraylist (or other collection data type ) so that I can loop this ArrayList ( or collection data) to get the FK of contact tabel and location table from address table.
Because I need the 2 PK to do the second query

What method can i get the FK of contact and location (the data) from first query when the first query return a arraylist( a collectiondata )?

I try to casting the result of the arraylist e.g. (Address)resultArraylsit.get(0) in order to get the data in the arraylist.
But it fail

Can anyone help me?
1-to-many-and-1-to-many.png
[Thumbnail for 1-to-many-and-1-to-many.png]
1 to many 1 to many DB ER Diagarm
 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to ranch Mr jacky chan!

In this forum, There are special places for database:
https://coderanch.com/forums/f-78/ORM
https://coderanch.com/forums/f-3/JDBC
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abalfazl hossein wrote:Welcome to ranch Mr jacky chan!

Agree

In this forum, There are special places for database:
https://coderanch.com/forums/f-78/ORM
https://coderanch.com/forums/f-3/JDBC

Agree here too. Moving thread.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic