Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to populate rows from database which are related to user entered info like prod. code in jtable

      Connection con=DriverManager.getConnection(url, user, pass);
  if (con!= null) {
     System.out.println("Connected");
  }
   String sql="select product_name, price from inventorytable where product_code=?";
   PreparedStatement pst=con.prepareStatement(sql);
   pst.setString(1,ProductCode.getText());
   ResultSet rs= pst.executeQuery();
   ResultSetMetaData rsmetadata=rs.getMetaData();
   int columns=rsmetadata.getColumnCount();
   DefaultTableModel dtm=new DefaultTableModel();  
   Vector columns_name=new Vector();
   Vector data_rows=new Vector();
   for(int i=1; i<=columns;i++){
   columns_name.addElement(rsmetadata.getColumnName(i));
   }
   dtm.setColumnIdentifiers(columns_name);
   while(rs.next()){
    data_rows=new Vector();
    for(int j=1;j<=columns;j++){
     data_rows.addElement(rs.getString(j));
    }
    dtm.addRow(data_rows);
}
BillTable.setModel(dtm);

}
Sign In or Register to comment.