⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phototable.java

📁 这是基于jsp的相册管理系统。数据库是mysql
💻 JAVA
字号:
package huitong.util.db;

import huitong.javabean.*;
import java.util.*;
import java.sql.*;
public class PhotoTable 
{
	public boolean addPhoto(AlbumPhoto photo)
	{// 
		if (photo == null)
		{
			return false;
		}
		String insertSQL ="insert into photo(photoId,photo_albumId,photoName,photoAlt,photoSuffix)" +
				"values(" +"'" +photo.getPhotoId()+"',"+"'" +photo.getPhoto_albumId()+"',"+
				 "'" +photo.getPhotoName()+"',"+"'" +photo.getPhotoAlt()+"',"+"'" +photo.getPhotoSuffix()+"'"+
				")";
		System.out.println(" PhtotTable in addPhoto() " + insertSQL);
		if (new Connecter().insert(insertSQL))
			return true;
		return false;
	}
	public Iterator<AlbumPhoto> getPhotos(String albumId,String userName)
	{//注意:图片路径的形成
		/*if (albumId == null)
		{
			return null;
		}*/
		String sql = "select * from photo where photo_albumId like '"+albumId+"%'";
			//"select * from photo where photo_albumId='"+albumId+"'";
		System.out.println("in PhtotTable getPhotos() " + sql);
		ResultSet result = new Connecter().getResultSet(sql);
		try 
		{  
			if (result != null)
			{  
				HashSet set = new HashSet();
				AlbumPhoto photo = null;
				while (result.next())
				{
					System.out.println("in while " + result.getRow());
					photo = new AlbumPhoto().getPhoto(result,userName);
					set.add(photo);
				}
				return set.iterator();
			}
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	public AlbumPhoto getPhoto(String useName,String albumId,String photoId)
	{
		String sql = "select * from photo where photo_albumId like '"+albumId+"%' and photoId like '"+photoId+"%'";
		System.out.println("in PhtotTable getPhoto() " + sql);
		ResultSet result = new Connecter().getResultSet(sql);
		try 
		{  
			if (result != null && result.next())
			{  
				
				AlbumPhoto photo = new AlbumPhoto().getPhoto(result,useName);
				return photo;
			}
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	public void delPhoto(String albumId,String photoId)
	{
		if (albumId == null || photoId == null)
		{
			return;
		}
		String sql = " delete from photo where  photoId like'"+photoId+"%' and photo_albumId like '"+albumId+"%'";
		System.out.println(" in PhotoTale delPhoto " + sql);
		new Connecter().delete(sql);
	}
	public int   modify(AlbumPhoto photo,String oldAlbumId)
	{  
		if (photo ==  null)
		{
			return 0;
		}
		String sql = " update photo set photo_albumId ='"+photo.getPhoto_albumId()+"', photoName ='"+encoding(photo.getPhotoName())+"', photoAlt='"+encoding(photo.getPhotoAlt())+"' where  photoId like'"+photo.getPhotoId()+"%' and photo_albumId like '"+oldAlbumId+"%'";
		System.out.println(" in PhotoTale modify " + sql);
		return new Connecter().update(sql);
	}
	public String encoding(String str)
	{
		try
		{
			return str = new String(str.getBytes("iso-8859-1"));
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -