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


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 AddPhotosDao { 
	private Connection conn = null; 
 
	private PreparedStatement pstmt = null; 
 
	private ResultSet rs = null; 
	//查看是否有重名的文件 
	public int repeat(String file_name) { 
		int num = 0; 
		conn = ConnectionPool.getConnection(); 
		String sql = "select filename from photos where filename=? "; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, file_name); 
			rs = pstmt.executeQuery(); 
			if (rs.next()) { 
				num = 3; 
			} 
		} catch (SQLException e) { 
 
			e.printStackTrace(); 
		} 
		return num; 
 
	} 
	 
	// 记录上传的文件信息 
	public int uploadPhoto(String photo_title, String photo_content, String url, 
			 String username, String filename) { 
		int num = 0; 
		conn = ConnectionPool.getConnection(); 
		String sql = "insert into photos(photo_title,photo_content,url,username,filename) values (?,?,?,?,?)"; 
		try { 
			pstmt = conn.prepareStatement(sql); 
			pstmt.setString(1, photo_title); 
			pstmt.setString(2, photo_content); 
			pstmt.setString(3, url); 
			pstmt.setString(4, username); 
			pstmt.setString(5, filename); 
			num = pstmt.executeUpdate(); 
		} catch (SQLException e) { 
 
			e.printStackTrace(); 
		} 
		if (conn != null) { 
			try { 
				conn.close(); 
				if (pstmt != null) { 
					pstmt.close(); 
				} 
			} catch (SQLException e) { 
 
				e.printStackTrace(); 
			} 
		} 
		return num; 
 
	} 
 
}