catch(Exceptione){e.printStackTrace();count=-1;}finally{DButil.closeCon();}returncount;}publicstaticbooleanisExist(Stringsql)//某条记录是否存在{booleanflag=false;try{con=DButil.getConnection();stat=con.createStatement();rs=stat.executeQuery(sql);if(rs.next()){flag=true;//存在,设置返回值为true}
-4-
}catch(Exceptione){e.printStackTrace();flag=false;//发生任何异常,置返回结果为false}finally{DButil.closeCon();}returnflag;}publicstaticintdelUser(Stringuid)//删除用户{intcount=0;//设置返回值,此值记录被删除的用户拥有的联系人数量Vector
vpid=newVector();//存放pid的集合一个用户对应多个联系人try{con=DButil.getConnection();stat=con.createStatement();rs=stat.executeQuery("selectpidfromlxywhereuid='"+uid+"'");while(rs.next()){Stringpid=rs.getString(1);vpid.add(pid);}stat=con.createStatement();for(Strings:vpid){//循环删除每个联系人的相册stat.executeUpdate("deletefromphotowherepid='"+s+"'");}//在联系人联系人表中删除每个联系人count=stat.executeUpdate("deletefromlxywhereuid='"+uid+"'");//在用户表中删除用户stat.executeUpdate("deletefromuserwhereuid='"+uid+"'");}catch(Exceptione){e.printStackTrace();}finally{DButil.closeCon();}returncount;//返回删除了多少个联系人}publicstaticVectorgetNode(Stringuser,Stringcondition)//根据条件得到节点名称列表{
-5-
Vectornode=newVector();StringpatternStr=";";//拆分条件的正则式String[]scon=condition.split(patternStr);try{con=getConnection();stat=con.createStatement();if(scon.length==1&;&;scon[0].equals("uid")){//得到当前用户下有多少个分组rs=stat.executeQuery("selectdistinctpgroupfromlxywhereuid='"+user.trim()+"'");}elseif(scon.length==1){//得到当前联系人下相册里照片名列表rs=stat.executeQuery("selectphotonamefromphotowherepid="+"(selectpidfromlxywhereuid='"+user.trim()+"'andpname='"+scon[0].trim()+"')");}elseif(scon.length==2){//得到分组里的联系人列表rs=stat.executeQuery("selectpnamefromlxywhereuid='"+user.trim()+"'andpgroup='"+scon[1].trim()+"'");}while(rs.next()){Strings=rs.getString(1);node.add(s);}}catch(Exceptione){e.printStackTrace();}finally{DButil.closeCon();//关闭数据库连接}returnnode;}//************************分组**************************************publicstaticintdelGroup(Stringuser,Stringgroup)//删除分组功能实现{intcount=0;
-6-
Vectorvpid=newVector();try{con=getConnection();stat=con.createStatement();rs=stat.executeQuery("selectpidfr