www.pudn.com > Jsp-Blog.rar > ShowPhotoDao.java, change:2010-05-26,size:1107b


package myblog.dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
 
import myblog.commons.ConnectionPool; 
import myblog.entity.Photos; 
 
public class ShowPhotoDao { 
	public Connection conn = null; 
 
	public PreparedStatement pstmt = null; 
 
	public ResultSet rs = null; 
 
	public ArrayList<Photos> showPhotos(String username) { 
		ArrayList<Photos> list = new ArrayList<Photos>(); 
		conn = ConnectionPool.getConnection(); 
		String sql = "select photo_id,photo_title,url,photo_content,createdate from photos where username=? "; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, username); 
			rs = pstmt.executeQuery(); 
			while (rs.next()) { 
				Photos photo = new Photos(rs.getString("photo_id"), rs 
						.getString("photo_title"), null, rs.getString("url"), 
						rs.getString("photo_content"), null, null, rs 
								.getString("createdate")); 
				list.add(photo); 
			} 
		} catch (SQLException e) { 
			e.printStackTrace(); 
		} 
		return list; 
	} 
 
}