![](/img/trans.png)
[英]How to display Image form JTable into JLabel or from database to JLabel using JTable mouse click event?
[英]Updating data in mySQL database using JTable in netbeans with mouse click event
我在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);
}
}
}
查看https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseEvent.html
單擊兩次不會使點擊計數為2-嘗試按一下鼠標按鈕1,按一下鼠標按鈕2,然后釋放按鈕
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.