Hi all

I am programming a database-related application in Java(with msaccess). I have to facilitate several different types of queries, but I'd like to use the same JTable to display the results of each query (one at a time, of course).

Initially the Jtable display all records.

JTable tableview;
dataModel=new DefaultTableModel(details,heading);
tableview = new JTable(dataModel);
tableview.setEnabled(true);
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
dis=new JScrollPane(tableview,v,h);
dis.setBounds(30,200,900,500);
c.add(dis);
dis.setVisible(true);

I have one combo box. that contain several pin number. If i select one pin number then the Jtable display that particular pin number records only.

rs2=st2.executeQuery("Select * from account where pin_number="+s);
int i=0;
while(rs2.next())
{
   //assign the value to details[][];
}
dataModel=new DefaultTableModel(details,heading);
tableview = new JTable(dataModel);

I could not find any methods to update the contents of the JTable. I tried creating a new JTable object and adding that to the container.but nothing worked.

please help me.

you can use for loop to collect all the values from JTable i have used this for my project hope this may be helpful to u

for(int i1=0;i1<rows;i1++)
				{
						rs.next();
						for(int j1=0;j1<8;j1++)
						{
							data1[i1][j1]=rs.getString(j1+1);
						}
				}
				JTable table=new JTable(data1,Colheads);
				int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
				int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
				
				JScrollPane jsp=new JScrollPane(table,v,h);
				
		
			 getContentPane().add(jsp);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.