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


package myblog.dao; 
 
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
 
import myblog.commons.ConnectionPool; 
 
public class AddFavoriteLogDao { 
	public Connection conn = null; 
 
	public PreparedStatement pstmt = null; 
	 
	public ResultSet rs=null; 
	//查看是否已经添加过了 
	public int repeatFavoriteLog(  String logid) { 
		int number = 0; 
		conn = ConnectionPool.getConnection(); 
		String sql = "select log_id from favorite where log_id=?"; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, logid); 
			rs = pstmt.executeQuery(); 
			if(rs.next()){ 
				number=1; 
			} 
		} catch (SQLException e) { 
 
			e.printStackTrace(); 
		} 
		return number; 
	} 
	//添加到收藏 
	public int addFavoriteLog( String username, String logid) { 
		int number = 0; 
		conn = ConnectionPool.getConnection(); 
		String sql = "insert into favorite(username,log_id) values(?,?)"; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, username); 
			pstmt.setString(2, logid);	 
			number = pstmt.executeUpdate(); 
		} catch (SQLException e) { 
 
			e.printStackTrace(); 
		} 
		return number; 
	} 
 
}