如何利用jtable删除数据库一条信息-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

如何利用jtable删除数据库一条信息

蛮大人123 2016-03-25 18:41:56 1114
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 USERACCOUNT,String USERNAME,String NICKNAME,String PASSWORD,int SEX,String PHONE,
String EMAIL, String REGION,String MYINFO,String HEADPIC,int 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(1,u.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:
}    
SQL 数据库
分享到
取消 提交回答
全部回答(1)
  • 蛮大人123
    2019-07-17 19:14:57
    if(e.getSource==jbutton2) {
    int rownum = jtable.getSelectRow();
    //得到选定行,然后执行删除操作
    sql = delete from t_UserInfo where ,u.getUSERACCOUNT() =tablemodel.getValueAt(rownum,0)
    0 0
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题
推荐课程