资源简介
JAVA网络相册,可以实现照片的上传下载,增加删除,数据库的连接等。是java程序设计的一个重要课题
代码片段和文件信息
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import domain.Album;
public class AlbumDao {
//添加
public static Boolean add(final Album book) throws Exception {
JDBCTemplate t = new Transaction() {
@Override
protected Boolean doTransaction(Connection conn) throws Exception {
PreparedStatement ps = conn
.prepareStatement(“insert into album values(????)“);
ps.setString(1 book.id);
ps.setString(2 book.name);
ps.setString(3 book.owner);
ps.setString(4 book.des);
return ps.execute();
}
};
return t.execute();
}
//获取
public static Album get(final String id) throws Exception {
JDBCTemplate q = new Query() {
@Override
protected Album doQuery(Connection conn) throws Exception {
PreparedStatement ps = conn
.prepareStatement(“select * from album where id=?“);
ps.setString(1 id);
ps.execute();
ResultSet rs = ps.getResultSet();
Album book = null;
if (rs.next()) {
book = new Album();
book.id = rs.getString(“id“);
book.name = rs.getString(“name“);
book.owner = rs.getString(“owner“);
book.des = rs.getString(“des“);
}
return book;
}
};
return q.execute();
}
// 获取全部
public static List getAll() throws Exception {
JDBCTemplate> q = new Query>() {
@Override
protected List doQuery(Connection conn) throws Exception {
List books = new ArrayList();
PreparedStatement ps = conn
.prepareStatement(“select * from album“);
ps.execute();
ResultSet rs = ps.getResultSet();
while (rs.next()) {
Album book = new Album();
book.id = rs.getString(“id“);
book.name = rs.getString(“name“);
book.owner = rs.getString(“owner“);
book.des = rs.getString(“des“);
books.add(book);
}
return books;
}
};
return q.execute();
}
// 修改
public static Boolean update(final Album book final String oldId)
throws Exception {
JDBCTemplate t = new Transaction() {
@Override
protected Boolean doTransaction(Connection conn) throws Exception {
PreparedStatement ps = conn
.prepareStatement(“update album set id=?name=?owner=?des=? where id=?“);
ps.setString(1 book.id);
ps.setString(2 book.name);
ps.setString(3 book.owner);
ps.setString(4 book.des);
ps.setString(5 oldId);
return ps.execute();
}
};
return t.execute();
}
// 删除
public static Boolean delete(final String id) throws Exception {
JDBCTemplate t = new Transaction() {
@Override
protected Boolean doTransaction(Connection conn) throws Exception {
PreparedStatement ps = conn
.prepareStatement(“delete from album where id=?“);
ps.setString(1 id);
return ps.execute();
}
};
return t.execute();
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 661 2013-12-08 00:28 online_photo_album\.classpath
文件 1015 2013-12-22 15:09 online_photo_album\.project
目录 0 2014-12-10 00:00 online_photo_album\.settings\
文件 491 2013-12-02 17:44 online_photo_album\.settings\.jsdtscope
文件 389 2013-12-22 14:10 online_photo_album\.settings\org.eclipse.core.resources.prefs
文件 357 2013-12-02 17:44 online_photo_album\.settings\org.eclipse.jdt.core.prefs
文件 506 2013-12-22 15:09 online_photo_album\.settings\org.eclipse.wst.common.component
文件 335 2013-12-02 17:44 online_photo_album\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2013-12-02 17:44 online_photo_album\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2013-12-02 17:44 online_photo_album\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2014-12-10 00:00 online_photo_album\build\
目录 0 2014-12-10 00:00 online_photo_album\build\classes\
目录 0 2014-12-10 00:00 online_photo_album\build\classes\dao\
文件 1415 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao$1.class
文件 1638 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao$2.class
文件 1820 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao$3.class
文件 1524 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao$4.class
文件 1261 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao$5.class
文件 1817 2014-12-09 20:51 online_photo_album\build\classes\dao\AlbumDao.class
文件 1755 2014-12-09 21:50 online_photo_album\build\classes\dao\JDBCTemplate.class
文件 1415 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao$1.class
文件 1638 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao$2.class
文件 1820 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao$3.class
文件 1524 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao$4.class
文件 1261 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao$5.class
文件 1817 2014-12-09 20:51 online_photo_album\build\classes\dao\PhotoDao.class
文件 1062 2014-12-09 20:51 online_photo_album\build\classes\dao\Query.class
文件 1232 2014-12-09 20:51 online_photo_album\build\classes\dao\Transaction.class
目录 0 2014-12-10 00:00 online_photo_album\build\classes\domain\
文件 1044 2014-12-09 20:51 online_photo_album\build\classes\domain\Album.class
文件 1044 2014-12-09 20:51 online_photo_album\build\classes\domain\Photo.class
............此处省略41个文件信息
评论
共有 条评论