先说问题
select count(lunch_id) from swTelList 这条语句就是求出这个表中有多少条记录 我现在不知道怎么写这个DAO方法,就是说 我在页面上调用这个方法的时候就能得到这个表中有多少记录的数字 谢谢大家~~帮帮忙 请大家把这个DAO方法写一下
select count(lunch_id) from swTelList 这条语句就是求出这个表中有多少条记录 我现在不知道怎么写这个DAO方法,就是说 我在页面上调用这个方法的时候就能得到这个表中有多少记录的数字 谢谢大家~~帮帮忙 请大家把这个DAO方法写一下
Query q=hibernateSession.createQuery("select count(s.lunchId) from swTelList s");
List list=q.list();
return (Integer)list.get(0);
}
public int count(){
int count=0;
String sql="select count(lunch_id) from swTelList";
conn=this.getConnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
if(rs.next())
{
count=rs.getInt(1);
}
return count;
}
public Integer payEmolumentCount() throws Exception{
return ((Long)hibernateSession.createQuery("select count(s.lunchId) from swTelList s").uniqueResult()).intValue();
}
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select count(lunch_id) from swTelList";
ps = conn.prepareStatement(sb.toString());
rs = ps.executeQuery();
int count = 0;
if(rs.next()){
count = rs.getInt(1);
}
return count;
}
// TODO Auto-generated method stub
int i=0;
// 参数集合
List condition = new ArrayList();
// sql语句
String sql = "select count(jobId) as num from tb_job where 1=1";
// 条件
//编号
if (null != job.getNumber() && !"".equals(job.getNumber())) {
sql += " and number like ?";
condition.add("%"+job.getNumber()+"%");
}
//公司名称
if (null != job.getCompanyName() && !"".equals(job.getCompanyName())) {
sql += " and companyName like ?";
condition.add("%"+job.getCompanyName()+"%");
}
//项目名称
if (null != job.getProjectName() && !"".equals(job.getProjectName())) {
sql += " and projectName like ?";
condition.add("%"+job.getProjectName()+"%");
}
//当天工作
if (null != job.getTjob() && !"".equals(job.getTjob())) {
sql += " and tjob like ?";
condition.add("%"+job.getTjob()+"%");
}
//完成情况
if ( job.getCondition()>0 ) {
sql += " and condition = ?";
condition.add(job.getCondition());
}
//解决方案
if (null != job.getProblemSolve() && !"".equals(job.getProblemSolve())) {
sql += " and problemSolve like ?";
condition.add("%"+job.getProblemSolve()+"%");
}
//备注
if (null != job.getRe() && !"".equals(job.getRe())) {
sql += " and re like ?";
condition.add("%"+job.getRe()+"%");
}
//时间
if (null != job.getTimes() && !"".equals(job.getTimes())) {
sql += " and times like ?";
condition.add("%"+job.getTimes()+"%");
}
// 执行查询
Result result = super.searchTemplete(sql, condition);
SortedMap[] map=result.getRows();
if(map.length>0)
{
i=Integer.parseInt(map[0].get("num").toString());
}
// 清空
sql = null;
condition = null;
return i;
}
int count=0;
String sql="select count(lunch_id) from swTelList";
conn=this.getConnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
if(rs.next())
{
count=rs.getInt(1);
}
return count;
}
private String buildString(Map<String, Object> map) {
StringBuffer conditionString = new StringBuffer();
if(map.containsKey("t1")) {
conditionString.append(" and T.t1 = '").append(map.get("t1")).append("'");
}
if(map.containsKey("t2")) {
conditionString.append(" T.t2 like'%").append(map.get("t2")).append("%'");
}
return conditionString.toString();
}
public int getCountT(Map<String, Object> map) {
BigDecimal bigNum = null;
Session hibernateSession = getSession();
try {
String queryString = "select count(*) from Table T where 1 = 1"
.concat(this.buildString(map));
bigNum = (BigDecimal) hibernateSession.createSQLQuery(queryString).uniqueResult();
if(bigNum != null) {
return bigNum.intValue();
}
}catch (Exception ex) {
ex.printStackTrace();
}finally {
hibernateSession.close();
}
return 0;
}
// TODO Auto-generated method stub
Transaction trans = null;
Session session = HibernateSessionFactory.getSession();
trans = session.beginTransaction();
int m = Integer.parseInt(session.createSQLQuery(sql).list().get(0)
.toString());
trans.commit();
HibernateSessionFactory.closeSession();
return m;
}