如何使用查询select * from tableXXX where status='1'
制作TableView
如果status = 1数据显示在jtable中
否则如果status = 0数据未在jtable中显示
或如何在状态从1更新为0后刷新jtable
答案 0 :(得分:0)
这个mycode
public class ViewDapur extends JInternalFrame implements ListenerDapur, ListSelectionListener{
private static final long serialVersionUID = -1108049190501656840L;
Connection konek;
Statement state;
//private ControllerDapur controllermak,controllermin;
private ModelDapur modelmak,modelmin;
private TableModelDapur tableModelmak, tableModelmin;
private JTable table;
private JTable tablemak;
private JTable tablemin;
public JTable getInputTable(){
return table;
}
public ViewDapur() {
setSize(1320, 590);
setTitle("DATA ORDERAN TRIPLE SIX");
setMaximizable(false);
setIconifiable(true);
setClosable(true);
setResizable(true);
setFrameIcon(new ImageIcon(ViewDapur.class.getResource("/com/sun/javafx/scene/web/skin/Undo_16x16_JFX.png")));
setBorder(new MatteBorder(2, 2, 2, 2, (Color) Color.MAGENTA));
setNormalBounds(new Rectangle(20, 0, 0, 0));
//controllermak = new ControllerPramusaji();
tableModelmak = new TableModelDapur();
modelmak = new ModelDapur();
modelmak.setListener(this);
//controllermak.setModel(modelmak);
//controllermin = new ControllerPramusaji();
tableModelmin = new TableModelDapur();
modelmin = new ModelDapur();
modelmin.setListener(this);
//controllermin.setModel(modelmin);
init();
tablemak.setModel(tableModelmak);
tablemak.getTableHeader().setReorderingAllowed(false);
tablemin.setModel(tableModelmin);
tablemin.getTableHeader().setReorderingAllowed(false);
try {
loadDatabasemak();
} catch (Exception ex) {
// TODO: handle exception
}
try {
loadDatabasemin();
} catch (Exception ex) {
// TODO: handle exception
}
/* Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
viewTabelMakanan("1");
viewTabelMinuman("1");
}
});
timer.start();timer.setRepeats(false);
*/ //refreshTablemamin();
//viewTabelMakanan("1");
//viewTabelMinuman("1");
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
//Timer timer = new Timer(1000, new ActionListener() {
// public void actionPerformed(ActionEvent e) {
ViewDapur frame = new ViewDapur();
frame.setVisible(true);
// }
// });
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private void init(){
JPanel panel = new JPanel();
panel.setBackground(new Color(119, 136, 153));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "......"));
getContentPane().add(panel);
panel.setLayout(null);
tablemak = new JTable();
tablemak.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"No Meja", "Menu", "Jumlah", "No Antri"
}
));
JPanel panel_2 = new JPanel();
panel_2.setBounds(10, 11, 640, 540);
panel_2.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Daftar Order Makanan"));
panel_2.setLayout(null);
panel_2.add(tablemak);
panel.add(panel_2);
JScrollPane scrollPane2 = new JScrollPane(tablemak,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane2.setBounds(10, 26, 616, 502);
panel_2.add(scrollPane2);
scrollPane2.setViewportView(tablemak);
JPanel panel_1 = new JPanel();
panel_1.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Daftar Order Minuman"));
panel_1.setBounds(660, 11, 650, 537);
panel.add(panel_1);
panel_1.setLayout(null);
tablemin = new JTable();
tablemin.setBounds(241, 24, 0, 0);
panel_1.add(tablemin);
JScrollPane scrollPane = new JScrollPane(tablemin,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(10, 25, 627, 501);
panel_1.add(scrollPane);
scrollPane.setViewportView(tablemin);
}
private void loadDatabasemak() throws ErrorInfo, SQLException{
DAOdapur daovi = UtilGlobal.getDAOdapur();
tableModelmak.setList(daovi.selectAll());
}
private void loadDatabasemin() throws ErrorInfo, SQLException{
DAOdapur daovi = UtilGlobal.getDAOdapur();
tableModelmin.setList(daovi.selectAll2());
}
@Override
public void valueChanged(ListSelectionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void onDelete() {
// TODO Auto-generated method stub
}
@Override
public void onChange(ModelDapur model) {
// TODO Auto-generated method stub
}
public void refreshTablemamin() {
tablemak.revalidate();
tablemak.repaint();
tablemak.getSelectionModel().clearSelection();
tablemin.revalidate();
tablemin.repaint();
tablemin.getSelectionModel().clearSelection();
tableModelmak.fireTableDataChanged();
tableModelmin.fireTableDataChanged();
}
public void viewTabelMakanan(String status){
//mejahe="";
try {
konek = Koneksi.getKoneksi();
state = konek.createStatement();
String query = "select * from tbtrans where katmenu='MAKANAN' AND stord='"+status+"' AND stdpr='0'";
ResultSet result= state.executeQuery(query);
while(result.next()){
Dapur p = new Dapur();
p.setNokey(result.getString("nokey"));
p.setNovisitor(result.getString("novisitor"));
p.setNomeja(result.getInt("nomeja"));
p.setNoantri(result.getInt("noantri"));
p.setAddedpeg(result.getString("addedpeg"));
p.setKdmc(result.getInt("kdmc"));
p.setMncafe(result.getString("mncafe"));
p.setKatmenu(result.getString("katmenu"));
p.setQty(result.getDouble("qty"));
p.setHrg(result.getDouble("hrg"));
p.setSubtotal(result.getDouble("subtotal"));
p.setWorder(result.getString("worder"));
p.setStord(result.getInt("stord"));
p.setWsaji(result.getString("wsaji"));
p.setStdpr(result.getInt("stdpr"));
p.setStkasir(result.getInt("stkasir"));
p.setPegkasir(result.getString("pegkasir"));
tableModelmak.add(p);
tableModelmak.fireTableDataChanged();
}
}
catch(Exception e){
e.printStackTrace();
}
//Pramusaji p = new Pramusaji();
}
public void viewTabelMinuman(String status){
//mejahe="";
try {
konek = Koneksi.getKoneksi();
state = konek.createStatement();
String query = "select * from tbtrans where katmenu='MINUMAN' AND stord='"+status+"' AND stdpr='0'";
ResultSet result= state.executeQuery(query);
while(result.next()){
Dapur p = new Dapur();
p.setNokey(result.getString("nokey"));
p.setNovisitor(result.getString("novisitor"));
p.setNomeja(result.getInt("nomeja"));
p.setNoantri(result.getInt("noantri"));
p.setAddedpeg(result.getString("addedpeg"));
p.setKdmc(result.getInt("kdmc"));
p.setMncafe(result.getString("mncafe"));
p.setKatmenu(result.getString("katmenu"));
p.setQty(result.getDouble("qty"));
p.setHrg(result.getDouble("hrg"));
p.setSubtotal(result.getDouble("subtotal"));
p.setWorder(result.getString("worder"));
p.setStord(result.getInt("stord"));
p.setWsaji(result.getString("wsaji"));
p.setStdpr(result.getInt("stdpr"));
p.setStkasir(result.getInt("stkasir"));
p.setPegkasir(result.getString("pegkasir"));
tableModelmin.add(p);
tableModelmin.fireTableDataChanged();
}
}
catch(Exception e){
e.printStackTrace();
}
//Pramusaji p = new Pramusaji();
}
}