Do join operation in single query between payments
and record
table and retrieve result on JTable
.
How to put row into one JTable using the data inside of the two database
-
29-06-2022 - |
Question
guys? help me with my problem. I want to have a one jtable that populates data using two table from database. i have two methods inside my class Apple..
Class Apple;
public void table(){
try{
String id = num.getText();
rs = stat.executeQuery("SELECT * FROM payments;");
Vector<String> header = new Vector<String>();
header.add("PAYMENT");
header.add("AMOUNT");
header.add("MODIFIER");
header.add("DATE MODIFIED");
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while(rs.next()) {
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // loop
dtm.setDataVector(data , header);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(0,0,490,250);
panel.add(scrollPane);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}//tble
that's the first method inside class Apple, and rs = stat.executeQuery("SELECT * FROM payments;");
is the first database table i want to retrieve the data and insert inside my jtable.. after it insert inside my jtable i have another method that will retrieve data from another database table..
public void table(){
try{
String id = num.getText();
rs = stat.executeQuery("SELECT * FROM record where idNum ='"+id+"';");
while(rs.next()){
Vector<Object> row = new Vector<Object>();
row.add(rs.getString("description"));
row.add(rs.getString("amount"));
row.add(rs.getString("remarks"));
row.add(rs.getString("date"));
data.add(row);
} // while
dtm.setDataVector(data , header);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(0,0,490,250);
panel.add(scrollPane);
validate();
}catch(Exception e){
System.out.println("Error in table: "+e);
}//try and catch
}//tble
this is the second methd inside the class apple.. i want its data to be added into my jtable and not deleting the previous data inserted inside the jtable..sorry for my poor english grammar..hope you understand what i mean..
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow