- 浏览: 80578 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
li445970924:
我每次做项目是就只用了一个Dao 用的Spring框架的D ...
DAO的一个讨论问题 -
iKing:
引用form提交的数据校验应该是放在action中进行校验的
...
DAO的一个讨论问题 -
arafat:
carrot 写道最近的项目设计中,淡化dao层设计,dao层 ...
DAO的一个讨论问题 -
lzg3267373:
iKing 写道<div class="quo ...
DAO的一个讨论问题 -
iKing:
<div class="quote_title ...
DAO的一个讨论问题
上编是关于DAO的讨论问题,通过这个一个讨论在这一过程当中我们每一人持的不同的看法,我想的是不管怎么样的DAO分层与整合的设计,都要依据我们的软件项目来衡量,从软件的角度上来看,就是要开发一个很完美的,效率高,运行很稳定的软件,为我们的每一个客户服务,因为客户关心的是他们的数据与数据的安全,而不是在于你们使用的怎么的代码逻辑设计思想,今天我就来做一个DAO的全面的总结吧,首先通过一个JDBC首先的一个DAO整合方法,在这个DAO的整合方法中,把我们经常定义的小类DAO方法收样到大的DAO整合方法中来,进行他们的执行操作,包含对数据库的SQL的执行控制(指的SQL的执行次数,SQL每秒执行规定的数据量)能实现到这样的,能大大的减少我们的数据库的频繁执行SQL的操作,在这样大DAO方法包含了 数据的增加,删除,更新,修改在每个小DAO的方法中主要直接转进参数进来,大的DAO法执行了在把结果集给小DAO,这里说明,不是Service层,而是DAO,上一编中 有人讲是Serviece层,我在这里说不是它,而是DAO层。假如我们以后的业务修改了,我们的DAO就没有进行大刀的修改与操作,主要关心我们的业务控制逻辑层就是了。竟然我们的DAO可以这样写,那么我们的Service层可以这样写,不过要根据自己的软件要求。就这搁笔吧,请看代码如下:
<!!!-----------DAO--->
public abstract class BaseHibernateDao extends HibernateDaoSupport
{
public BaseHibernateDao()
{
}
protected abstract Class getEntityClass();
public Object get(Serializable id)
{
Object o = getHibernateTemplate().get(getEntityClass(), id);
if(o == null)
throw new ObjectRetrievalFailureException(getEntityClass(), id);
else
return o;
}
public List getAll()
{
return getHibernateTemplate().loadAll(getEntityClass());
}
public void removeByHql(String hql)
{
Query q = getSession().createQuery(hql);
q.executeUpdate();
}
public void save(Object o)
{
getHibernateTemplate().save(o);
}
public void update(Object o)
{
getHibernateTemplate().update(o);
}
public void remove(Serializable id)
{
remove(get(id));
}
public void remove(int id)
{
remove(get(new Integer(id)));
}
public void remove(Object o)
{
getHibernateTemplate().delete(o);
}
public List find(String hsql)
{
return getHibernateTemplate().find(hsql);
}
public List find(String hsql, Object value)
{
return getHibernateTemplate().find(hsql, value);
}
public List find(String hsql, Object values[])
{
return getHibernateTemplate().find(hsql, values);
}
public Object findBy(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.eq(name, value));
return criteria.uniqueResult();
}
public List findAllBy(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.eq(name, value));
return criteria.list();
}
public List findAllByLike(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.like(name, value));
return criteria.list();
}
public List findAllBy(Map filter)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
return criteria.list();
}
public Page pagedQuery(String hql, int pageNo, int pageSize)
{
return pagedQuery(hql, null, pageNo, pageSize);
}
public Page pagedQuery(String hql, Object args[], int pageNo, int pageSize)
{
int end = hql.indexOf("order");
end = end != -1 ? end : hql.length();
String sql = (new StringBuilder()).append("select count(*) as total ").append(hql.substring(hql.indexOf("from"), end)).toString();
int total = 0;
try
{
List l = getHibernateTemplate().find(sql, args);
total = ((Integer)l.get(0)).intValue();
}
catch(Exception ex)
{
logger.error(ex);
}
return pagedQuery(hql, args, pageNo, pageSize, total);
}
public Page pagedQuery(String hql, Object args[], int pageNo, int pageSize, int total)
{
if(hql == null)
throw new IllegalArgumentException("NULL is not a valid HQL string");
Query query = getSession().createQuery(hql);
if(args != null)
{
for(int i = 0; i < args.length; i++)
query.setParameter(i, args[i]);
}
return HqlPage.getHibernatePageInstance(query, pageNo, pageSize, total);
}
public List findAllBy(Map filter, Map sortMap, int rowStart, int rowDisplayed)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
sortCriteria(criteria, sortMap);
criteria.setProjection(null);
criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
criteria.setFirstResult(rowStart);
criteria.setMaxResults(rowDisplayed);
return criteria.list();
}
protected void filterCriteria(Criteria criteria1, Map map)
{
}
private void sortCriteria(Criteria criteria, Map sortMap)
{
if(!sortMap.isEmpty())
{
for(Iterator iterator = sortMap.keySet().iterator(); iterator.hasNext();)
{
String fieldName = iterator.next().toString();
String orderType = sortMap.get(fieldName).toString();
if("asc".equalsIgnoreCase(orderType))
criteria.addOrder(Order.asc(fieldName));
else
criteria.addOrder(Order.desc(fieldName));
}
}
}
public int getCount(Map filter)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
Integer count = (Integer)criteria.setProjection(Projections.rowCount()).uniqueResult();
return count.intValue();
}
protected final Log logger = LogFactory.getLog(getClass());
}
<!---DaoSupport---->
public class BaseHibernateSuport extends HibernateDaoSupport
{
public BaseHibernateSuport()
{
}
public int getCount(String hsql, Object obj[])
throws HibernateException, SQLException
{
int total = 0;
try
{
List l = getHibernateTemplate().find(hsql, obj);
total = ((Integer)l.get(0)).intValue();
}
catch(Exception ex)
{
logger.error(ex);
}
return total;
}
public Vector swap(List list)
{
if(list != null)
{
Object obj = list.get(list.size() - 1);
Vector ret = new Vector();
ret.add(obj);
list.remove(list.size() - 1);
ret.addAll(list);
return ret;
} else
{
return null;
}
}
}
<!--DAO--->
public abstract class BaseDAO
{
public BaseDAO()
{
conn = null;
needClosed = null;
isSharedCon = false;
needClosed = new Vector();
isSharedCon = false;
}
public Connection getCurrentConnection()
{
if(conn == null)
conn = getConnection(CURRENTCONNECTIONSTYLE);
return conn;
}
public Connection getConnection()
throws SQLException
{
return getConnection(CURRENTCONNECTIONSTYLE);
}
public void setCurrentConnection(Connection conn)
throws Exception
{
if(this.conn == null)
{
this.conn = conn;
} else
{
closeConnection();
this.conn = conn;
}
}
public Connection getConnection(int style)
{
try
{
if(style == 0)
conn = OaUtil.getConnection();
else
if(style == 1)
{
DriverManager.registerDriver(new OracleDriver());
conn = DriverManager.getConnection((new StringBuilder()).append("jdbc:oracle:thin:@").append(hostname).append(":").append(port).append(":").append(dbSID).toString(), username, password);
}
}
catch(Exception e)
{
System.out.println(e.toString());
return null;
}
System.out.println("get database_connection successfully!");
return conn;
}
public boolean begin()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.setAutoCommit(false);
return true;
}
public boolean commit()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.commit();
return true;
}
public boolean rollback()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.rollback();
return true;
}
public ResultSet OpenSQL(String sql)
throws SQLException
{
if(conn == null)
getCurrentConnection();
conn.setAutoCommit(true);
Statement stmt = conn.createStatement(RESULTSETTYLE, RESULTSETCONCURRENCY);
ResultSet rs = stmt.executeQuery(sql);
needClosed.addElement(stmt);
needClosed.addElement(rs);
return rs;
}
public int executeSQL(String sql, boolean CommitAtOnce)
throws SQLException
{
Statement stmt;
int ret;
stmt = null;
ret = 0;
if(conn == null)
getCurrentConnection();
if(CommitAtOnce)
begin();
stmt = conn.createStatement();
ret = stmt.executeUpdate(sql);
if(CommitAtOnce)
commit();
if(stmt != null)
stmt.close();
break MISSING_BLOCK_LABEL_106;
Exception e;
e;
if(CommitAtOnce)
rollback();
if(stmt != null)
stmt.close();
break MISSING_BLOCK_LABEL_106;
Exception exception;
exception;
if(stmt != null)
stmt.close();
throw exception;
return ret;
}
public int executeSQL(String sql)
throws SQLException
{
return executeSQL(sql, true);
}
public void closeConnection()
{
if(conn != null && !isSharedCon)
try
{
for(int i = 0; i < needClosed.size(); i++)
{
Object obj = needClosed.get(i);
if(obj instanceof Statement)
{
((Statement)obj).close();
continue;
}
if(obj instanceof PreparedStatement)
{
((PreparedStatement)obj).close();
continue;
}
if(obj instanceof ResultSet)
((ResultSet)obj).close();
}
needClosed.clear();
conn.close();
conn = null;
}
catch(Exception e)
{
System.out.println((new StringBuilder()).append("baseDAO.closeConnection() exception:").append(e.toString()).toString());
}
}
public abstract Object getFromRSCurRow(ResultSet resultset);
public Vector getBeansFromResultSet(ResultSet rs)
{
Vector ret;
ret = new Vector();
for(; rs.next(); ret.addElement(getFromRSCurRow(rs)));
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.getBeansFromResultSet exception:").append(e.toString()).toString());
return null;
}
public Vector getBeansFromResultSet(ResultSet rs, SearchInfo searchinfo)
{
if(!rs.next())
return new Vector();
Vector ret;
int page;
int row;
int rowcount;
ret = new Vector();
page = searchinfo.getCurPage();
if(page < 1)
page = 1;
row = (page - 1) * searchinfo.getPageSize() + 1;
rowcount = 0;
rowcount = 1;
_L1:
if(rowcount >= row)
break MISSING_BLOCK_LABEL_94;
if(rs.next())
break MISSING_BLOCK_LABEL_88;
searchinfo.setCurPage(0);
searchinfo.setRowsCount(rowcount);
return ret;
rowcount++;
goto _L1
int i = 0;
i = 0;
do
{
if(i >= searchinfo.getPageSize() && searchinfo.getPageSize() != 0)
break;
ret.addElement(getFromRSCurRow(rs));
if(!rs.next())
break;
rowcount++;
i++;
} while(true);
if(i != searchinfo.getPageSize())
searchinfo.setPageSize(++i);
searchinfo.setCurPage(page);
while(rs.next())
rowcount++;
searchinfo.setRowsCount(rowcount);
int tmpI = 0;
if(rowcount == 0)
tmpI = 0;
else
if(searchinfo.getPageSize() == 0)
{
tmpI = 1;
} else
{
double tmpD = (double)rowcount / (double)searchinfo.getPageSize();
tmpI = (int)tmpD;
if(tmpD > (double)tmpI)
tmpI++;
}
searchinfo.setPageCount(tmpI);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.getBeansFromResultSet exception:").append(e.toString()).toString());
return null;
}
public PreparedStatement createUpdateStatement(String sql)
{
PreparedStatement ret;
if(conn == null)
getCurrentConnection();
ret = conn.prepareStatement(sql);
needClosed.addElement(ret);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.CreatePreparedStatement exception:").append(e.toString()).toString());
return null;
}
public PreparedStatement createQueryStatement(String sql)
{
PreparedStatement ret;
if(conn == null)
getCurrentConnection();
ret = conn.prepareStatement(sql);
needClosed.addElement(ret);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.CreatePreparedStatement exception:").append(e.toString()).toString());
return null;
}
public ResultSet executeQuery(PreparedStatement prstms)
{
ResultSet rs;
rs = prstms.executeQuery();
needClosed.addElement(rs);
return rs;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO. executeQuery exception:").append(e.toString()).toString());
return null;
}
public int executeUpdate(PreparedStatement prstms)
{
int ret = prstms.executeUpdate();
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO. executeupdate exception:").append(e.toString()).toString());
return 0;
}
public Vector getNeedClosed()
{
return needClosed;
}
public void AddNeedClosed(Vector v)
{
needClosed.addAll(v);
}
public void ConnectTo(BaseDAO dao)
{
conn = dao.getCurrentConnection();
needClosed = dao.getNeedClosed();
isSharedCon = true;
}
public boolean getIsSharedConnection()
{
return isSharedCon;
}
<!!!-----------DAO--->
public abstract class BaseHibernateDao extends HibernateDaoSupport
{
public BaseHibernateDao()
{
}
protected abstract Class getEntityClass();
public Object get(Serializable id)
{
Object o = getHibernateTemplate().get(getEntityClass(), id);
if(o == null)
throw new ObjectRetrievalFailureException(getEntityClass(), id);
else
return o;
}
public List getAll()
{
return getHibernateTemplate().loadAll(getEntityClass());
}
public void removeByHql(String hql)
{
Query q = getSession().createQuery(hql);
q.executeUpdate();
}
public void save(Object o)
{
getHibernateTemplate().save(o);
}
public void update(Object o)
{
getHibernateTemplate().update(o);
}
public void remove(Serializable id)
{
remove(get(id));
}
public void remove(int id)
{
remove(get(new Integer(id)));
}
public void remove(Object o)
{
getHibernateTemplate().delete(o);
}
public List find(String hsql)
{
return getHibernateTemplate().find(hsql);
}
public List find(String hsql, Object value)
{
return getHibernateTemplate().find(hsql, value);
}
public List find(String hsql, Object values[])
{
return getHibernateTemplate().find(hsql, values);
}
public Object findBy(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.eq(name, value));
return criteria.uniqueResult();
}
public List findAllBy(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.eq(name, value));
return criteria.list();
}
public List findAllByLike(String name, Object value)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
criteria.add(Restrictions.like(name, value));
return criteria.list();
}
public List findAllBy(Map filter)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
return criteria.list();
}
public Page pagedQuery(String hql, int pageNo, int pageSize)
{
return pagedQuery(hql, null, pageNo, pageSize);
}
public Page pagedQuery(String hql, Object args[], int pageNo, int pageSize)
{
int end = hql.indexOf("order");
end = end != -1 ? end : hql.length();
String sql = (new StringBuilder()).append("select count(*) as total ").append(hql.substring(hql.indexOf("from"), end)).toString();
int total = 0;
try
{
List l = getHibernateTemplate().find(sql, args);
total = ((Integer)l.get(0)).intValue();
}
catch(Exception ex)
{
logger.error(ex);
}
return pagedQuery(hql, args, pageNo, pageSize, total);
}
public Page pagedQuery(String hql, Object args[], int pageNo, int pageSize, int total)
{
if(hql == null)
throw new IllegalArgumentException("NULL is not a valid HQL string");
Query query = getSession().createQuery(hql);
if(args != null)
{
for(int i = 0; i < args.length; i++)
query.setParameter(i, args[i]);
}
return HqlPage.getHibernatePageInstance(query, pageNo, pageSize, total);
}
public List findAllBy(Map filter, Map sortMap, int rowStart, int rowDisplayed)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
sortCriteria(criteria, sortMap);
criteria.setProjection(null);
criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
criteria.setFirstResult(rowStart);
criteria.setMaxResults(rowDisplayed);
return criteria.list();
}
protected void filterCriteria(Criteria criteria1, Map map)
{
}
private void sortCriteria(Criteria criteria, Map sortMap)
{
if(!sortMap.isEmpty())
{
for(Iterator iterator = sortMap.keySet().iterator(); iterator.hasNext();)
{
String fieldName = iterator.next().toString();
String orderType = sortMap.get(fieldName).toString();
if("asc".equalsIgnoreCase(orderType))
criteria.addOrder(Order.asc(fieldName));
else
criteria.addOrder(Order.desc(fieldName));
}
}
}
public int getCount(Map filter)
{
Criteria criteria = getSession().createCriteria(getEntityClass());
filterCriteria(criteria, filter);
Integer count = (Integer)criteria.setProjection(Projections.rowCount()).uniqueResult();
return count.intValue();
}
protected final Log logger = LogFactory.getLog(getClass());
}
<!---DaoSupport---->
public class BaseHibernateSuport extends HibernateDaoSupport
{
public BaseHibernateSuport()
{
}
public int getCount(String hsql, Object obj[])
throws HibernateException, SQLException
{
int total = 0;
try
{
List l = getHibernateTemplate().find(hsql, obj);
total = ((Integer)l.get(0)).intValue();
}
catch(Exception ex)
{
logger.error(ex);
}
return total;
}
public Vector swap(List list)
{
if(list != null)
{
Object obj = list.get(list.size() - 1);
Vector ret = new Vector();
ret.add(obj);
list.remove(list.size() - 1);
ret.addAll(list);
return ret;
} else
{
return null;
}
}
}
<!--DAO--->
public abstract class BaseDAO
{
public BaseDAO()
{
conn = null;
needClosed = null;
isSharedCon = false;
needClosed = new Vector();
isSharedCon = false;
}
public Connection getCurrentConnection()
{
if(conn == null)
conn = getConnection(CURRENTCONNECTIONSTYLE);
return conn;
}
public Connection getConnection()
throws SQLException
{
return getConnection(CURRENTCONNECTIONSTYLE);
}
public void setCurrentConnection(Connection conn)
throws Exception
{
if(this.conn == null)
{
this.conn = conn;
} else
{
closeConnection();
this.conn = conn;
}
}
public Connection getConnection(int style)
{
try
{
if(style == 0)
conn = OaUtil.getConnection();
else
if(style == 1)
{
DriverManager.registerDriver(new OracleDriver());
conn = DriverManager.getConnection((new StringBuilder()).append("jdbc:oracle:thin:@").append(hostname).append(":").append(port).append(":").append(dbSID).toString(), username, password);
}
}
catch(Exception e)
{
System.out.println(e.toString());
return null;
}
System.out.println("get database_connection successfully!");
return conn;
}
public boolean begin()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.setAutoCommit(false);
return true;
}
public boolean commit()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.commit();
return true;
}
public boolean rollback()
throws SQLException
{
if(isSharedCon)
return true;
if(conn == null)
getCurrentConnection();
conn.rollback();
return true;
}
public ResultSet OpenSQL(String sql)
throws SQLException
{
if(conn == null)
getCurrentConnection();
conn.setAutoCommit(true);
Statement stmt = conn.createStatement(RESULTSETTYLE, RESULTSETCONCURRENCY);
ResultSet rs = stmt.executeQuery(sql);
needClosed.addElement(stmt);
needClosed.addElement(rs);
return rs;
}
public int executeSQL(String sql, boolean CommitAtOnce)
throws SQLException
{
Statement stmt;
int ret;
stmt = null;
ret = 0;
if(conn == null)
getCurrentConnection();
if(CommitAtOnce)
begin();
stmt = conn.createStatement();
ret = stmt.executeUpdate(sql);
if(CommitAtOnce)
commit();
if(stmt != null)
stmt.close();
break MISSING_BLOCK_LABEL_106;
Exception e;
e;
if(CommitAtOnce)
rollback();
if(stmt != null)
stmt.close();
break MISSING_BLOCK_LABEL_106;
Exception exception;
exception;
if(stmt != null)
stmt.close();
throw exception;
return ret;
}
public int executeSQL(String sql)
throws SQLException
{
return executeSQL(sql, true);
}
public void closeConnection()
{
if(conn != null && !isSharedCon)
try
{
for(int i = 0; i < needClosed.size(); i++)
{
Object obj = needClosed.get(i);
if(obj instanceof Statement)
{
((Statement)obj).close();
continue;
}
if(obj instanceof PreparedStatement)
{
((PreparedStatement)obj).close();
continue;
}
if(obj instanceof ResultSet)
((ResultSet)obj).close();
}
needClosed.clear();
conn.close();
conn = null;
}
catch(Exception e)
{
System.out.println((new StringBuilder()).append("baseDAO.closeConnection() exception:").append(e.toString()).toString());
}
}
public abstract Object getFromRSCurRow(ResultSet resultset);
public Vector getBeansFromResultSet(ResultSet rs)
{
Vector ret;
ret = new Vector();
for(; rs.next(); ret.addElement(getFromRSCurRow(rs)));
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.getBeansFromResultSet exception:").append(e.toString()).toString());
return null;
}
public Vector getBeansFromResultSet(ResultSet rs, SearchInfo searchinfo)
{
if(!rs.next())
return new Vector();
Vector ret;
int page;
int row;
int rowcount;
ret = new Vector();
page = searchinfo.getCurPage();
if(page < 1)
page = 1;
row = (page - 1) * searchinfo.getPageSize() + 1;
rowcount = 0;
rowcount = 1;
_L1:
if(rowcount >= row)
break MISSING_BLOCK_LABEL_94;
if(rs.next())
break MISSING_BLOCK_LABEL_88;
searchinfo.setCurPage(0);
searchinfo.setRowsCount(rowcount);
return ret;
rowcount++;
goto _L1
int i = 0;
i = 0;
do
{
if(i >= searchinfo.getPageSize() && searchinfo.getPageSize() != 0)
break;
ret.addElement(getFromRSCurRow(rs));
if(!rs.next())
break;
rowcount++;
i++;
} while(true);
if(i != searchinfo.getPageSize())
searchinfo.setPageSize(++i);
searchinfo.setCurPage(page);
while(rs.next())
rowcount++;
searchinfo.setRowsCount(rowcount);
int tmpI = 0;
if(rowcount == 0)
tmpI = 0;
else
if(searchinfo.getPageSize() == 0)
{
tmpI = 1;
} else
{
double tmpD = (double)rowcount / (double)searchinfo.getPageSize();
tmpI = (int)tmpD;
if(tmpD > (double)tmpI)
tmpI++;
}
searchinfo.setPageCount(tmpI);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.getBeansFromResultSet exception:").append(e.toString()).toString());
return null;
}
public PreparedStatement createUpdateStatement(String sql)
{
PreparedStatement ret;
if(conn == null)
getCurrentConnection();
ret = conn.prepareStatement(sql);
needClosed.addElement(ret);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.CreatePreparedStatement exception:").append(e.toString()).toString());
return null;
}
public PreparedStatement createQueryStatement(String sql)
{
PreparedStatement ret;
if(conn == null)
getCurrentConnection();
ret = conn.prepareStatement(sql);
needClosed.addElement(ret);
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO.CreatePreparedStatement exception:").append(e.toString()).toString());
return null;
}
public ResultSet executeQuery(PreparedStatement prstms)
{
ResultSet rs;
rs = prstms.executeQuery();
needClosed.addElement(rs);
return rs;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO. executeQuery exception:").append(e.toString()).toString());
return null;
}
public int executeUpdate(PreparedStatement prstms)
{
int ret = prstms.executeUpdate();
return ret;
Exception e;
e;
System.out.println((new StringBuilder()).append("BaseDAO. executeupdate exception:").append(e.toString()).toString());
return 0;
}
public Vector getNeedClosed()
{
return needClosed;
}
public void AddNeedClosed(Vector v)
{
needClosed.addAll(v);
}
public void ConnectTo(BaseDAO dao)
{
conn = dao.getCurrentConnection();
needClosed = dao.getNeedClosed();
isSharedCon = true;
}
public boolean getIsSharedConnection()
{
return isSharedCon;
}
相关推荐
在"Servlet01:jsp结束,servlet的配置和生命周期"这个主题中,我们将讨论以下几个关键知识点: 1. **Servlet简介**:Servlet是Java类,遵循Servlet接口,用于扩展服务器的功能,特别是Web服务器。它们可以接收和...
在分页查询时,DAO需要根据每页的起始位置和结束位置来构造SQL查询语句,比如: ```java String sql = "SELECT * FROM table LIMIT ?, ?"; PreparedStatement pstmt = connection.prepareStatement(sql); pstmt.set...
List<Data> dataList = dao.getPageData(currentPage, pageSize); request.setAttribute("dataList", dataList); request.setAttribute("currentPage", currentPage); request.setAttribute("totalPage", dao....
很抱歉,但根据您提供的信息,“daodao流程图1”的描述和标签中并没有具体的IT知识点,只有不可读的字符序列,这使得无法生成详细的知识点解释。通常,流程图在IT行业中可能涉及到软件开发的流程,比如敏捷开发的...
public List<User> getUsersByCollection(Collection collection); } ``` 这个方法接受一个Collection类型的参数,用于传递数组或集合类。 在Mapper文件中,我们可以使用foreach标签来遍历集合类,例如: ```xml ...
泛型DAO模式通过抽象化设计,增强了程序的复用性和简化了编程语言,同时在程序运行结束后进行类型检查,避免了运行时的问题,并提高了运行速度。 文章进一步讨论了泛型DAO模式的查询功能设计。查询功能是泛型DAO...
其次,持久化(Persist)是将数据保存到非易失性存储(如硬盘)上的过程,使得数据在程序运行结束或系统重启后仍然存在。在Java中,JPA(Java Persistence API)和Hibernate是常用的持久化框架。JPA是Java官方提供的...
HTML文档由一系列的元素组成,每个元素都有自己的开始和结束标签,如`<p>`(段落)和`<img>`(图像)。HTML5是目前广泛使用的版本,增加了许多新特性,如离线存储、音频/视频处理以及更好的表单控件等,大大提升了...
在逻辑推理方面,我们可以讨论一些逻辑推理问题,例如分析问题和逻辑证明等。在这个例子中,我们可以讨论一个逻辑推理问题:A 到 B 的店去买香烟。A 付给 B100 元,但 B 无零钱找补,就拿去 C 处兑换零钱;B 回来将...
会议结束后,这些决策被正式传达给了服务器端软件开发小组,他们可以根据这些信息开始初步的开发工作。通过这样的协作方式,团队可以确保每个部分的工作都能按计划进行,从而提高项目的整体进度和质量。 总结来说,...
书中既详实地介绍了iBATIS的设计理念和基础知识,也讨论了动态SQL、高速缓存、DAD框架等高级主题,还讲解了iBATIS在实际开发中的应用。书的最后给出了一个设计优雅、层次清晰的示例程序JGameStore,该示例涵盖全书的...
实训期间,我保持了良好的学习态度,准时出勤,积极参与讨论,及时完成日报,主动帮助同学解决问题。通过这次实训,我对SSM框架有了更深的认识,理解了session和cookie的使用,掌握了图片验证码、MD5加密和过滤器等...
这里我们将围绕"java秒杀项目源码-seckill"这个项目进行详细的分析和讨论。 首先,`seckill`项目源码是基于Java实现的秒杀系统的业务层代码,包含了处理秒杀业务的核心逻辑。项目中通常会包含以下几个关键模块: 1...
下面将详细讨论这些可能出现的问题以及解决方法。 首先,让我们了解一下Struts和Spring框架的基本概念。Struts是一个基于MVC(模型-视图-控制器)架构的Java Web框架,主要用于处理HTTP请求和控制业务逻辑。而...
接着,我们讨论一下** dao, service, action, model, pageModel**这些概念,它们是软件开发中的常见组成部分: 1. **DAO (Data Access Object)**:数据访问对象是用于处理数据库交互的类,它将业务逻辑与数据操作...
【Java程序员面试知识点...6. **结束面试**:最后阶段,表现出对公司和职位的热情,提出高质量的问题,礼貌道别。 这些面试知识点和技巧对于准备Java程序员的面试至关重要,全面理解和熟练掌握将大大提升面试成功率。
在实训中遇到问题并解决问题的过程,也是学习的重要部分。尽管在数据库连接和数据插入上遇到了困难,但通过不断地尝试和调试,学员们逐渐理解了这些技术的精髓。尽管最终没有完全解决,但这种坚持和探索的精神对于...
可能有文章实体类、评论实体类,以及相应的服务和DAO接口,用于CRUD操作。前端页面则使用模板引擎如FreeMarker或Thymeleaf渲染,提供良好的用户体验。 活动发布功能可能涉及到事件管理,用户可以创建、参与、查看...
在这个案例中,开题报告可能会讨论药店管理的现状、问题以及ASP技术的优势,明确系统开发的目标和计划。 结题PPT是项目结束时的总结,通常包含项目完成情况、主要成果、遇到的问题及解决方案、未来改进方向等内容。...