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 Combination of tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Combination of tables" Watch "Combination of tables" New topic
Author

Combination of tables

denice
Greenhorn

Joined: Jul 18, 2004
Posts: 3
Does anyone know how to combine 4 tables into a brand new table?? Any sugguestion on how to do it??

-thx-
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
thenice,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Well, you need to have some relationship between the columns in different tables to know which row in one table combines with a row in another table, and then you basically do a join.

something like

SELECT a.col1, a.col2, b.col1, b.col2 FROM a, b WHERE a.col1=b.col2

Once you get a ResultSet from this query, iternate through it and do inserts in the new table. Best to use a PreparedStatement with SQL something like

INSERT INTO new_table(a_col1, a_col2, b_col1) VALUES (?,?,?)

and setting the parameters as you iterate through each row.

HTH

Danephew


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
Or you can use sql UNION but i guess you need to follow some guidelines
like same column names, same aritmetic expressions, aggregate functions and so on...thus you don't need to create and insert it into a new table. All the tables are combined as one resultset.
 
Consider Paul's rocket mass heater.
 
subject: Combination of tables