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


package myblog.dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.util.ArrayList; 
 
import myblog.commons.ConnectionPool; 
import myblog.entity.Logs; 
 
public class ShowFavoriteLogsDao { 
	public Connection conn = null; 
	public PreparedStatement pstmt=null; 
 
	public Statement stmt = null; 
 
	public ResultSet rs = null; 
 
	public ArrayList<Logs> showFavoriteLog(String username) { 
		ArrayList<Logs> list = new ArrayList<Logs>(); 
		conn = ConnectionPool.getConnection(); 
		String sql = "select logid, logtitle, a.username, logcontent, createdate from log a, favorite b where rownum < 10 and a.logid = b.log_id and  b.username =?  order by createdate desc "; 
		try { 
		pstmt=conn.prepareStatement(sql); 
		pstmt.setString(1,username); 
		rs=pstmt.executeQuery(); 
			while (rs.next()) { 
				Logs log = new Logs(rs.getString("logid"), rs 
						.getString("logtitle"), rs.getString("logcontent"), rs 
						.getString("username"), rs.getString("createdate")); 
				list.add(log); 
			} 
		} catch (SQLException e) { 
 
			e.printStackTrace(); 
		} 
		return list; 
 
	} 
}