我在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);
}
}
}
答案 0 :(得分:1)
查看https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseEvent.html
点击两次不会使点击计数为二 - 尝试按鼠标按钮一次,按鼠标按钮两次,然后释放按钮