⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frienddao.java

📁 使用JAVA编写的博客
💻 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();
	}
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -