问题描述
- 如何利用jtable删除数据库一条信息
- public class userinfo {
private String USERACCOUNT;
private String USERNAME;
private String NICKNAME;
private String PASSWORD;
private int SEX;
private String PHONE;
private String EMAIL;
private String REGION;
private String MYINFO;
private String HEADPIC;
private int DEPTID;
public userinfo(){}
public userinfo(String USERACCOUNTString USERNAMEString NICKNAMEString PASSWORDint SEXString PHONE
String EMAIL String REGIONString MYINFOString HEADPICint DEPTID)
{
this.USERACCOUNT=USERACCOUNT;
this.USERNAME=USERNAME;
this.NICKNAME=NICKNAME;
this.PASSWORD=PASSWORD;
this.SEX=SEX;
this.PHONE=PHONE;
this.EMAIL=EMAIL;
this.REGION=REGION;
this.MYINFO=MYINFO;
this.HEADPIC=HEADPIC;
this.DEPTID=DEPTID;
}
public String getUSERACCOUNT(){
return USERACCOUNT;
}
public void setUSERACCOUNT(String USERACCOUNT){
this.USERACCOUNT=USERACCOUNT;
}
public String getUSERNAME(){
return USERNAME;
}
public void setUSERNAME(String USERNAME){
this.USERNAME=USERNAME;
}
public String getNICKNAME(){
return NICKNAME;
}
public void setNICKNAME(String NICKNAME){
this.NICKNAME=NICKNAME;
}
public String getPASSWORD(){
return PASSWORD;
}
public void setPASSWORD(String PASSWORD){
this.PASSWORD=PASSWORD;
}
public int getSEX(){
return SEX;
}
public void setSEX(int SEX){
this.SEX=SEX;
}
public String getPHONE(){
return PHONE;
}
public void setPHONE(String PHONE){
this.PHONE=PHONE;
}
public String getEMAIL(){
return EMAIL;
}
public void setEMAIL(String EMAIL){
this.EMAIL=EMAIL;
}
public String getREGION(){
return REGION;
}
public void setREGION( String REGION){
this.REGION=REGION;
}
public String getMYINFO(){
return MYINFO;
}
public void setMYINFO(String MYINFO){
this.MYINFO=MYINFO;
}
public String getHEADPIC(){
return HEADPIC;
}
public void setHEADPIC(String HEADPIC){
this.HEADPIC=HEADPIC;
}
public int getDEPTID(){
return DEPTID;
}
public void setDEPTID(int DEPTID){
this.DEPTID=DEPTID;
}
void show(){
System.out.print( USERACCOUNT+"" ""+USERNAME+"" ""+NICKNAME+"" ""+PASSWORD+"" ""+SEX+"" ""+PHONE+"" ""+
EMAIL+"" ""+REGION+"" ""+MYINFO+"" ""+HEADPIC+"" ""+DEPTID+"" ""+""n"");
}
}public void delete(userinfo u){Connection con=BaseDAO.getConnection();try{String sql =""delete from t_UserInfo where USERACCOUNT=? and USERNAME=? and NICKNAME=? and PASSWORD=? and SEX=? and PHONE=? and EMAIL=? and REGION=? and MYINFO=? and HEADPIC=? and DEPTID=? "";PreparedStatement pstmt=con.prepareStatement(sql);pstmt.setString(1u.getUSERACCOUNT() );pstmt.setString(2 u.getUSERNAME());pstmt.setString(3 u.getNICKNAME());pstmt.setString(4 u.getPASSWORD());pstmt.setInt(5 u.getSEX());pstmt.setString(6 u.getPHONE());pstmt.setString(7 u.getEMAIL());pstmt.setString(8 u.getREGION());pstmt.setString(9 u.getMYINFO());pstmt.setString(10 u.getHEADPIC());pstmt.setInt(11 u.getDEPTID());int num=pstmt.executeUpdate(); if(num>0){ System.out.println(""删除成功""); }else{ System.out.println(""删除失败""); } BaseDAO.closeStatement(pstmt); BaseDAO.closeConnection(con);}catch(Exception e){e.printStackTrace();}} private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:} 在jbutton2中添加什么样的代码才能实现鼠标选中jtable中的一行的时候点击删除,直接删除,而且连同数据库的一起删除![图片说明](http://img.ask.csdn.net/upload/201601/05/1451984879_753791.png)
解决方案
if(e.getSource==jbutton2) {
int rownum = jtable.getSelectRow();
//得到选定行,然后执行删除操作
sql = delete from t_UserInfo where u.getUSERACCOUNT() =tablemodel.getValueAt(rownum0)
………………
时间: 2024-10-02 22:08:30