我需要幫助,我到處尋找,但沒有成功,我正在創(chuàng)建 Java gui 應(yīng)用程序,它將有許多按鈕,這些按鈕將是一些類似的對象,并且具有來自 SQL 的名稱和價(jià)格,但是數(shù)量將是按鈕的點(diǎn)擊次數(shù),在計(jì)算出我需要刪除該列表的產(chǎn)品后,問題是一切正常,但是當(dāng)我嘗試創(chuàng)建新列表(即 DbutilsTableModel)時(shí),數(shù)量只是繼續(xù)從上一個(gè)列表!這是擦除按鈕的代碼,預(yù)計(jì)會將所有計(jì)數(shù)器重置為 0(零):JButton btnBrisiListu = new JButton("Brisi racun listu"); // Button for erasing the listbuttonGroup.add(btnBrisiListu);btnBrisiListu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String naredba1 = " UPDATE ArtikliRacun SET [Komada]= 0 "; String naredba = "SELECT [Naziv],[Komada],[Cena] from ArtikliRacun WHERE Komada > 0"; try { Statement stmt = konekcioniObj.createStatement(); stmt.executeUpdate(naredba1); ResultSet rs = stmt.executeQuery(naredba); table.setModel(DbUtils.resultSetToTableModel(rs)); System.out.println(rs); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }});這是按鈕的代碼(一些文章/產(chǎn)品) - 所有這些按鈕的代碼都是相同的:JButton button = new JButton("Jelen 0.33"); buttonGroup.add(button); button.setName("Jelen 0.33"); button.addActionListener(new ActionListener() { int komada = 0; public void actionPerformed(ActionEvent event) { komada++; String naredba1 = " UPDATE ArtikliRacun SET [Komada]='"+komada+"' WHERE Naziv ='"+button.getName()+"' "; String naredba = "SELECT [Naziv],[Komada],[Cena] from ArtikliRacun WHERE Komada > 0"; try { Statement stmt = konekcioniObj.createStatement(); stmt.executeUpdate(naredba1); ResultSet rs = stmt.executeQuery(naredba); table.setModel(DbUtils.resultSetToTableModel(rs)); System.out.println(rs); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
1 回答

躍然一笑
TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
就像是
UPDATE ArticlesAccount SET [Piece]=[Piece] + 1 WHERE Name ='"+button.getName()+"'
這是有效的!?。。≈x謝@MadProgrammer
添加回答
舉報(bào)
0/150
提交
取消