Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some question about Java Progarmming

 
jackyj chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to ranch Mr jacky chan!

In this forum, There are special places for database:
http://www.coderanch.com/forums/f-78/ORM
http://www.coderanch.com/forums/f-3/JDBC
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:Welcome to ranch Mr jacky chan!
Agree
In this forum, There are special places for database:
http://www.coderanch.com/forums/f-78/ORM
http://www.coderanch.com/forums/f-3/JDBC
Agree here too. Moving thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic