首页 > 解决方案 > 导航按钮在java netbeans中不起作用

问题描述

我正在用 java 表单创建简单的 crud 系统,由 6 个按钮保存,第一个,下一个,上一个,最后一个我附上了表单设计下面的屏幕截图。如果单击保存按钮数据成功保存。然后如果我先单击第一个按钮显示记录,如果我单击最后一个按钮,最后一个记录应该成功显示。如果单击下一个并且上一个按钮数据无法正常工作。

在此处输入图像描述

下一个按钮代码是这个

 String name = txtItem.getText();
       int qty = Integer.parseInt(txtQty.getText());
       int price = Integer.parseInt(txtPrice.getText());        
        try {
            Class.forName("com.mysql.jdbc.Driver");
              con = DriverManager.getConnection("jdbc:mysql://localhost/supers","root","");
              pst = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);                        
            String sql = "SELECT item,qty,price FROM stock";
            ResultSet rs = pst.executeQuery(sql);

           if  (rs.next())
           {
             name = rs.getString("item");
             qty  = rs.getInt("qty");                                
             price  = rs.getInt("price");                                  
              txtItem.setText(name);
              txtQty.setText(String.valueOf(qty));
              txtPrice.setText(String.valueOf(price));                  
           }
           else
           {
               rs.previous();
               JOptionPane.showMessageDialog(this,"end of the file");
           }


        } catch (ClassNotFoundException ex) {
            Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
        }

标签: java

解决方案


推荐阅读