?? phototable.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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -