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

📄 conferencedao.java

📁 该源码包括了基于J2EE的数据持久层设计,设计中使用了DAO,Service,等模式,并在Struts下进行了测试.
💻 JAVA
字号:
package org.conference.datapersistence.Dao;

import java.io.Serializable;

import javax.sql.DataSource;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import org.conference.datapersistence.Bo.ConferenceVO;
import org.conference.datapersistence.DaoMethod;

import org.javawing.component.dao.DataAccessException;
import org.javawing.component.jdbc.core.RowCallbackHandler;
import org.javawing.component.jdbc.core.support.JdbcDaoSupport;

public class ConferenceDao extends JdbcDaoSupport implements Serializable {
	private static final long serialVersionUID = 1L;

	public ConferenceDao(DataSource dataSource) {
		this.setDataSource(dataSource);
	}

	public List doFindbyMultiple(ConferenceVO conference) {
		final List ConferenceList = new ArrayList();
		HashMap attribute = new HashMap();
		attribute.put("tablename", "conference");
		attribute.put("ctitle_$", conference.getTitle());
		attribute.put("sdate_L", conference.getDatexj());
		attribute.put("edate_S", conference.getDatesj());
		attribute.put("clocation_$", conference.getAddress());
		attribute.put("organizer_$", conference.getOrganizer());
		String Query = DaoMethod.QueryBuilding(attribute);
		this.getJdbcTemplate().query(Query, new RowCallbackHandler() {
			public void processRow(ResultSet rs) throws SQLException {
				ConferenceVO conference = new ConferenceVO();
				SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
				conference.setId(rs.getInt("cid"));
				conference.setTitle(rs.getString("ctitle"));
				if (!(rs.getDate("edate")).equals(null)){
				conference.setEdateforconference(formater.format(
						rs.getDate("edate")).toString());
				}
				if (!(rs.getDate("sdate")).equals(null)){
					conference.setSdateforconference(formater.format(
							rs.getDate("sdate")).toString());
					}
				conference.setAddress(rs.getString("clocation"));
				conference.setUrl(rs.getString("curl"));
				conference.setOrganizer(rs.getString("organizer"));
				conference.setRealeasedate(rs.getString("pddate"));
				conference.setComments(rs.getString("comments"));
				ConferenceList.add(conference);
				conference = null;
			}
		});
		return ConferenceList;
	}

	public List doFindAll() {
		final List ConferenceList = new ArrayList();
		String Query = "select cid,ctitle,sdate,edate,clocation,curl,pddate,organizer,comments from conference order by sdate desc";
		this.getJdbcTemplate().query(Query, new RowCallbackHandler() {
			public void processRow(ResultSet rs) throws SQLException {
				ConferenceVO conference = new ConferenceVO();
				SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
				conference.setId(rs.getInt("cid"));
				conference.setTitle(rs.getString("ctitle"));
				conference.setSdateforconference(formater.format(
						rs.getDate("sdate")).toString());
				conference.setEdateforconference(formater.format(
						rs.getDate("edate")).toString());
				conference.setAddress(rs.getString("clocation"));
				conference.setUrl(rs.getString("curl"));
				conference.setOrganizer(rs.getString("organizer"));
				conference.setRealeasedate(rs.getString("pddate"));
				conference.setComments(rs.getString("comments"));
				ConferenceList.add(conference);
				conference = null;
			}
		});
		return ConferenceList;
	}

	public List doFindTopN(int n) {
		List ConferenceList = new ArrayList();
		final List Result = new ArrayList();
		ConferenceList = this.doFindAll();
		for (int i = 0; i <n ; i++) {
			Result.add(ConferenceList.get(i));
		}
		return Result;
	}
	
	public Object doFindbyId(final int id) {
		final List ConferenceList = new ArrayList();
		String Query = "select ctitle,sdate,edate,clocation,curl,pddate,organizer,comments from conference where cid="+id;
		this.getJdbcTemplate().query(Query, new RowCallbackHandler() {
			public void processRow(ResultSet rs) throws SQLException {
				ConferenceVO conference = new ConferenceVO();
				SimpleDateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
				conference.setId(id);
				conference.setTitle(rs.getString("ctitle"));
				conference.setSdateforconference(formater.format(
						rs.getDate("sdate")).toString());
				conference.setEdateforconference(formater.format(
						rs.getDate("edate")).toString());
				conference.setAddress(rs.getString("clocation"));
				conference.setUrl(rs.getString("curl"));
				conference.setOrganizer(rs.getString("organizer"));
				conference.setRealeasedate(rs.getString("pddate"));
				conference.setComments(rs.getString("comments"));
				ConferenceList.add(conference);
				conference = null;
			}
		});
		return ConferenceList.get(0);
	}

	public int doStore(ConferenceVO conference) throws DataAccessException {
		String storeQuery = null;
		storeQuery = "insert into conference(ctitle,edate,sdate,clocation,curl,pddate,organizer,comments)values('"
				+ conference.getTitle()
				+ "','"
				+ conference.getEdateforconference()
				+ "','"
				+ conference.getSdateforconference()
				+ "','"
				+ conference.getAddress()
				+ "','"
				+ conference.getUrl()
				+ "','"
				+ conference.getRealeasedate()
				+ "','"
				+ conference.getOrganizer()
				+ "','"
				+ conference.getComments()
				+ "')";
		return this.getJdbcTemplate().update(storeQuery);
	}
	public int doFindMaxConferenceid() {
		return   this.getJdbcTemplate().queryForInt("select max(cid) from conference");
		
	}

}

⌨️ 快捷键说明

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