gpt4 book ai didi

java - 使用netbeans中的JTable通过鼠标单击事件更新mySQL数据库中的数据

转载 作者:行者123 更新时间:2023-11-29 10:42:24 24 4
gpt4 key购买 nike

我正在 netbeans 中编写代码,其中当单击特定行时,mySQL 数据库中的数据会自动从“N”更新为“Y”。我编写了以下代码。请大家看看是不是有什么问题。尝试使用调试器,但它甚至没有进入点击计数循环。

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);
}

}
}

Here is mySql database description

最佳答案

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

单击两次不会使单击计数为两次 - 尝试按鼠标按钮一,按鼠标按钮二,然后释放按钮

关于java - 使用netbeans中的JTable通过鼠标单击事件更新mySQL数据库中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45230587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com