【问题标题】:How To Delete And Update Data From Table Layout如何从表格布局中删除和更新数据
【发布时间】:2022-07-21 18:31:30
【问题描述】:

Picture Of Table Layout Table

首先,您可以查看链接中的图片。我想通过单击“pilih aksi”来更新和删除表格行。任何人都可以帮助我吗?谢谢。

【问题讨论】:

  • 您好!很抱歉,我们需要您的minimal reproducible example。另外,您有没有tried to solve this question before asking? 如果有,请告诉我们您在这样做时遇到的问题和错误。最后,我喜欢你像一个忙碌的实习生一样与我们交谈,但事实上这是一个“问题出在这里,我的代码”线程使得这些指南毫无用处。

标签: java android-studio updates delete-row tablelayout


【解决方案1】:

更新过程:

对于这个过程,我们首先右键单击我们的表格并添加鼠标单击事件>鼠标单击事件。

在这个事件部分里面:

lbl_id.setText(jTable1.getValueAt(jTable1.getSelectedRow(),0).toString());
   txt_name.setText(jTable1.getValueAt(jTable1.getSelectedRow(),1).toString());
   txt_surname.setText(jTable1.getValueAt(jTable1.getSelectedRow(),2).toString());
   txt_email.setText(jTable1.getValueAt(jTable1.getSelectedRow(),3).toString());
   txt_password.setText(jTable1.getValueAt(jTable1.getSelectedRow(),4).toString());

总结一下,首先,我们将数据从表格发送到标签和文本字段字段。现在我们将label和textfield字段中的值保留在sql更新查询中的问号位置。我们在执行此操作时使用 PreparedStatement。

删除操作:

String id=lbl_id. getText ( ) ;
    
    
    
    String query= "DELETE FROM `users` WHERE id=?" ;
    PreparedStatement ps;
    try {
            ps=MyConnection. getConnection ( ) . prepareStatement ( query ) ;
            ps. setString ( 1 , id ) ;
            ps. executeUpdate ( ) ;
            if ( ps. executeUpdate ( ) == 0 ) {
                JOptionPane. showMessageDialog ( null, "Deleted" ) ;
                
            }
            get_value ( ) ;
            
    } catch ( Exception e ) {   
    }

我们对删除查询做同样的事情。这次我们只需要 id。所以我们刚刚得到了 id 值。该过程完成后,我们再次调用该函数从表中提取数据。因此,我们的表将在删除或更新后更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2011-07-30
    • 2015-12-22
    • 2018-08-26
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多