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
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()) {
customer le= new customer(lex.getInt("customerID"), lex.getInt("branchID"), lex.getString("acctype"), lex.getDouble("balance"));
}
while (cali.next()) {
customer cal= new customer(cali.getInt("customerID"), cali.getInt("branchID"), cali.getString("acctype"), cali.getDouble("balance"));
}
while (ohio.next()) {
customer ohi= new customer(ohio.getInt("customerID"), ohio.getInt("branchID"), ohio.getString("acctype"), ohio.getDouble("balance"));
}
while (ny.next()) {
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.