简体   繁体   English

在NetBeans中使用JTable通过鼠标单击事件更新mySQL数据库中的数据

[英]Updating data in mySQL database using JTable in netbeans with mouse click event

I am writing a code in netbeans wherein when clicked on a specific row the data is automatically updated from 'N' to 'Y' in mySQL database. 我在netbeans中编写代码,其中当单击特定行时,数据将在mySQL数据库中从“ N”自动更新为“ Y”。 I have written the following code. 我写了下面的代码。 Please see if there's anything wrong with it. 请查看是否有任何问题。 Tried using debugger, but it is not even going inside the click count loop. 使用调试器进行了尝试,但它甚至没有进入点击计数循环。

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {                                     
    // TODO add your handling code here:
    PreparedStatement ps;
    ResultSet rs;
    if(evt.getClickCount()==2){

        int getsel = jTable2.rowAtPoint(evt.getPoint());
        int value = Integer.parseInt(jTable2.getValueAt(getsel, 6).toString());
        try{

            ps = con.prepareStatement("select * from roomservice where guestid = "+value);
            rs = ps.executeQuery();
            if(rs.next()){
                String taskstatus = rs.getString("taskstatus");
                if(taskstatus.equalsIgnoreCase("Y")){

                    ps = con.prepareStatement("update roomservice set taskstatus = 'N' where guestid= "+value);
                    ps.executeUpdate();

                    JOptionPane.showMessageDialog(null, "updated task status");

                }else if(taskstatus.equalsIgnoreCase("N")){
                    ps = con.prepareStatement("update roomservice set taskstatus = 'Y' where guestid= "+value);
                    ps.executeUpdate();
                    JOptionPane.showMessageDialog(null, "updated task status");
                }
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }

    }
  }            

这是mySql数据库描述

Looking at https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseEvent.html 查看https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseEvent.html

clicking twice does not make the click count two - try press mouse button one , press mouse button two, then release buttons 单击两次不会使点击计数为2-尝试按一下鼠标按钮1,按一下鼠标按钮2,然后释放按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM