首页>代码>Java Web简化版交友网站平台>/WEB_08/src/dao/PicDAO.java
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;
import entity.Pic;

public class PicDAO {
	// 1.保存上传的照片
	public void save(Pic pic) throws Exception {
		Connection conn = DBUtil.getConnection();
		PreparedStatement prep = conn
				.prepareStatement("insert into f_pic values(null,?,?)");
		prep.setString(1, pic.getPicName());
		prep.setInt(2, pic.getUserId());
		prep.executeUpdate();
		DBUtil.close(conn);
	}

	// 2.获取相片的列表
	public List<Pic> findPics(int userId) throws Exception {
		List<Pic> pics = new ArrayList<Pic>();
		Connection conn = DBUtil.getConnection();
		PreparedStatement prep = conn
				.prepareStatement("select*from f_pic where userId=?");
		prep.setInt(1, userId);
		ResultSet rs = prep.executeQuery();
		while (rs.next()) {
			Pic pic = new Pic();
			pic.setId(rs.getInt("id"));
			pic.setPicName(rs.getString("picName"));
			pic.setUserId(userId);
			pics.add(pic);
		}
		DBUtil.close(conn);
		return pics;
	}

}
最近下载更多
asddwh  LV12 2023年12月29日
panadol  LV1 2023年12月28日
asadda  LV2 2023年6月27日
abcdert  LV1 2022年12月8日
1020132795  LV5 2022年9月2日
微信网友_6004958227304448  LV1 2022年6月16日
ahahhhhh  LV1 2022年2月19日
dcdc12  LV6 2021年12月21日
wwewww  LV4 2021年12月20日
张家军  LV1 2021年12月19日
最近浏览更多
西瓜哥哥  LV4 3月5日
asddwh  LV12 2023年12月29日
panadol  LV1 2023年12月28日
hanzhuohong  LV1 2023年12月25日
zeng1206  LV5 2023年12月23日
eqeqleqeqn  LV1 2023年12月22日
2036495585  LV9 2023年10月15日
yiy12345  LV2 2023年10月11日
zdmxjxj  LV9 2023年9月14日
husiyu  LV3 2023年9月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友