friend java_FriendDao.java

package com.yxq.dao;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import com.yxq.toolsbean.DB;

import com.yxq.valuebean.FriendBean;

public class FriendDao {

private DB connection = null;

public FriendDao() {

connection = new DB();

}

// 修改朋友

public boolean operationFriend(String operation,FriendBean single) {

String sql="";

if(operation==null)

operation="";

if(operation.equals("add"))

sql="insert into tb_friend values('"+single.getName()+"','"+single.getSex()+"','"+single.getOicq()+"','"+single.getBlog()+"')";

if(operation.equals("modify"))

sql="update tb_friend set friend_name='"+single.getName()+"',friend_sex='"+single.getSex()+"',friend_OICQ='"+single.getOicq()+"',friend_blog='"+single.getBlog()+"' where id="+single.getId();

if(operation.equals("delete"))

sql="delete from tb_friend where id="+single.getId();

boolean flag=connection.executeUpdate(sql);

return flag;

}

/**

* @功能 查询所有好友

*/

public List queryFriend(String type) {

String sql="";

if(type==null||type.equals("")||!type.equals("all"))

sql="select top 5 * from tb_friend order by friend_name DESC";

else

sql="select * from tb_friend order by friend_name DESC";

List list = new ArrayList();

FriendBean friendBean = null;

ResultSet rs = connection.executeQuery(sql);

try {

while (rs.next()) {

friendBean = new FriendBean();

friendBean.setId(rs.getInt(1));

friendBean.setName(rs.getString(2));

friendBean.setSex(rs.getString(3));

friendBean.setOicq(rs.getString(4));

friendBean.setBlog(rs.getString(5));

list.add(friendBean);

}

} catch (SQLException e) {

e.printStackTrace();

}

return list;

}

/**

* @功能 查询某个好友的详细信息

*/

public FriendBean queryFriendSingle(int id) {

FriendBean friendBean = null;

String sql = "select * from tb_friend where id=" + id;

ResultSet rs = connection.executeQuery(sql);

try {

while (rs.next()) {

friendBean = new FriendBean();

friendBean.setId(Integer.valueOf(rs.getString(1)));

friendBean.setName(rs.getString(2));

friendBean.setSex(rs.getString(3));

friendBean.setOicq(rs.getString(4));

friendBean.setBlog(rs.getString(5));

}

rs.close();

} catch (SQLException e) {

e.printStackTrace();

} finally{

connection.closed();

}

return friendBean;

}

public void closeConnection(){

connection.closed();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值