用对象填充JTable [英] populating JTable with with object

查看:98
本文介绍了用对象填充JTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试从4个不同的表中获取记录(假设它们位于不同的服务器上),并将它们存储在4个不同的结果集中。

然后我试图将这4个不同的结果集存储在4个不同的对象中。

此外,我试图在一个JTable中显示这4个对象。

任何人都可以指导我吗?

或者是否有任何方法可以用四种不同的结果集填充我的Jtable?



我的代码如下



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()) {


        //...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.

推荐答案

这篇关于用对象填充JTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆