库
{
int count=0;//声明返回值
try
{
con=DButil.getConnection();
stat=con.createStatement();
count=stat.executeUpdate(sql);
}
catch(Exception e)
{
e.printStackTrace();
count=-1;
}
finally{DButil.closeCon();}
return count;
}
public static boolean isExist(String sql)//某条记录是否存在
{
boolean flag=false;
try
{
con=DButil.getConnection();
stat=con.createStatement();
rs=stat.executeQuery(sql);
if(rs.next())
{
flag=true;//存在,设置返回值为true
}
}
catch(Exception e)
{
e.printStackTrace();
flag=false;//发生任何异常,置返回结果为false
}
finally{DButil.closeCon();}
return flag;
}
public static int delUser(String uid)//删除用户
{
int count=0;//设置返回值,此值记录被删除的用户拥有的联系人数量
Vector
vpid=new Vector();//存放pid的集合 一个用户对应多个联系人
try
{
con=DButil.getConnection();
stat=con.createStatement();
rs=stat.executeQuery("select pid from lxy where uid='"+uid+"'");
while(rs.next())
{
String pid=rs.getString(1);
vpid.add(pid);
}
stat=con.createStatement();
for(String s:vpid)
{//循环删除每个联系人的相册
stat.executeUpdate("delete from photo where pid='"+s+"'");
}
//在联系人联系人表中删除每个联系人
count=stat.executeUpdate("delete from lxy where uid='"+uid+"'");
//在用户表中删除用户
stat.executeUpdate("delete from user where uid='"+uid+"'");
}
catch(Exception e)
{
e.printStackTrace();
}
finally{DButil.closeCon();}
return count;//返回删除了多少个联系人
}
public static Vector getNode(String user,String condition)//根据条件得到节点名称列表
{
Vector node=new Vector();
String patternStr=";";//拆分条件的正则式
String[] scon=condition.split(patternStr);
try
{
con=getConnection();
stat=con.createStatement();
if(scon.length==1&&scon[0].equals("uid"))
{//得到当前用户下有多少个分组
rs=stat.executeQuery("select distinct pgroup from lxy where uid='"+user.trim()+"'");
}
else if(scon.length==1)
{//得到当前联系人下相册里照片名列表
rs=stat.executeQuery("select photoname from photo where pid = "+
"(select pid from lxy where uid='"+user.trim()+"'and pname='"+scon[0].trim()+"')");
}
else if(scon.length==2)
{//得到分组里的联系人列表
rs=stat.executeQuery("select pname from lxy where uid='"
+user.trim()+"'and pgroup='"+scon[1].trim()+"'");
}
while(rs.next())
{
String s=rs.getString(1);
node.add(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DButil.closeCon();//关闭数据库连接
}
return node;
}
//************************分组**************************************
public static int delGroup(String user,String group)//删除分组功能实现
{
int count=0;
Vector vpid=new Vector();
try
{
con=getConnection();
stat=con.createStatement();
rs=stat.executeQuery("select pid from lxy where pgroup='"+group+"'"
+"and uid='"+user+"'");
while(rs.next())
{
String pid=rs.getString(1);
vpid.add(pid);
}
stat=con.createStatement();
for(String s:vpid)
{
stat.executeUpdate("delete from photo where pid='"+s+"'");
}
count=stat.executeUpdate("delete from lxy where p