Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm trying to fetch records from 4 different table (assuming they are on different servers), and storing them in 4 different resultsets.
Then I'm trying to store these 4 different resultsets in 4 different object.
Further I'm trying to display these 4 objects in a single JTable.
Can anyone guide me on this?
or if there is any way using which I can populate my Jtable with four different resultsets?

My code is as followed

Java
 private void b_queryActionPerformed(java.awt.event.ActionEvent evt) {
 Connection con= null;
 ResultSet rs,lex,cali,ny,ohio = null;
 PreparedStatement ps, ps1,ps2,ps3 = null;
 String sql,sql1,sql2,sql3;
int rowCount = 0;
int columnCount = 0;
String clause = t_where.getText();
String TableName =t_tablename.getText();
try{
String sql = "select * from "+TableName+"_Lexington where "+clause;
String sql1 = "select * from "+TableName+"_California where "+clause;
String sql2= "select * from "+TableName+"_Ohio where "+clause;
String sql3 = "select * from "+TableName+"_NewYork where "+clause;
ps = con.prepareStatement(sql);
ps1=con.prepareStatement(sql1);
ps2=con.prepareStatement(sql2);
ps3=con.prepareStatement(sql3);
lex = ps.executeQuery();
cali = ps1.executeQuery();
ohio = ps2.executeQuery();
ny= ps3.executeQuery();
while (lex.next()) {


        //...Construct Object with people passing the Strings and Ints out of the DB
        customer le= new customer(lex.getInt("customerID"), lex.getInt("branchID"), lex.getString("acctype"), lex.getDouble("balance"));

     }
while (cali.next()) {


        //...Construct Object with people passing the Strings and Ints out of the DB
        customer cal= new customer(cali.getInt("customerID"), cali.getInt("branchID"), cali.getString("acctype"), cali.getDouble("balance"));

     }
while (ohio.next()) {


        //...Construct Object with people passing the Strings and Ints out of the DB
        customer ohi= new customer(ohio.getInt("customerID"), ohio.getInt("branchID"), ohio.getString("acctype"), ohio.getDouble("balance"));

     }
while (ny.next()) {


        //...Construct Object with people passing the Strings and Ints out of the DB
        customer n= new customer(ny.getInt("customerID"), ny.getInt("branchID"), ny.getString("acctype"), ny.getDouble("balance"));

     }
}
catch(Exception e){
    JOptionPane.showMessageDialog(null,"Error");
}



I'm sorry if I'm asking a stupid question. But I really need to learn this.
Posted
Comments
Shubhashish_Mandal 26-Apr-14 9:35am    
how you will render the 4 objects? 4 objects as a 4 row or 4 objects as a single row?
ineffable.an 26-Apr-14 12:18pm    
4 objects will have their own rows. all 4 resultsets should look like as one to the user basically. I hope I did answer to what you were asking

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900