File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Some question about Java Progarmming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Some question about Java Progarmming" Watch "Some question about Java Progarmming" New topic
Author

Some question about Java Progarmming

jackyj chan
Greenhorn

Joined: Apr 02, 2011
Posts: 2
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?



[Thumbnail for 1 to many and 1 to many.png]

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
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

Joined: Oct 13, 2005
Posts: 38793
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Some question about Java Progarmming