package com.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.toolsbean.DB; import com.valuebean.OptionBean; public class OptionDao { private DB mydb=null; public OptionDao(){ mydb=new DB(); } public List getOptions(){ String sql="select * from tb_option order by option_order"; List options=getList1(sql,null); return options; } public List getOptionsForDay(){ String sql="select o.*,t.num from tb_option as o left join (select voter_voteoption,count(id) as num from tb_voter where day(voter_votetime)=day(getdate()) group by voter_voteoption) t on o.id=t.voter_voteoption"; List options =getList2(sql,null); return options; } public List getOptionsForMonth(){ String sql="select o.*,t.num from tb_option as o left join (select voter_voteoption,count(id) as num from tb_voter where month(voter_votetime)=month(getdate()) group by voter_voteoption) t on o.id=t.voter_voteoption"; List options =getList2(sql,null); return options; } private List getList1(String sql,Object[] params){ List options=null; DB mydb=new DB(); mydb.doPstm(sql,params); try { ResultSet rs = mydb.getRs(); if(rs!=null){ options=new ArrayList(); while(rs.next()){ OptionBean single=new OptionBean(); single.setId(rs.getInt(1)); single.setOptionName(rs.getString(2)); single.setOptionBallot(rs.getInt(3)); single.setOptionOrder(rs.getInt(4)); options.add(single); } rs.close(); } } catch (SQLException e) { e.printStackTrace(); } return options; } private List getList2(String sql,Object[] params){ List options=null; DB mydb=new DB(); mydb.doPstm(sql,params); try { ResultSet rs = mydb.getRs(); if(rs!=null){ options=new ArrayList(); while(rs.next()){ OptionBean single=new OptionBean(); single.setId(rs.getInt(1)); single.setOptionName(rs.getString(2)); single.setOptionBallot(rs.getInt(5)); options.add(single); } rs.close(); } } catch (SQLException e) { e.printStackTrace(); } return options; } public int vote(int id){ int i=-1; String sql="update tb_option set option_ballot=option_ballot+1 where id=?"; Object[] params={id}; DB mydb=new DB(); mydb.doPstm(sql, params); try { i= mydb.getCount(); } catch (SQLException e) { i=-1; e.printStackTrace(); } return i; } public void closed(){ mydb.closed(); } }
最近下载更多
ming_123_9715 LV23
2022年11月27日
微信网友_6181845028360192 LV1
2022年10月19日
3273591624 LV6
2022年8月27日
evagsd LV6
2022年7月8日
chengjuan LV2
2022年6月29日
eniu_27 LV5
2022年5月30日
微信网友_5980754345857024 LV1
2022年5月30日
太菜了多吃肉 LV2
2022年4月18日
panpan2018ok LV9
2021年12月23日
taijh999 LV13
2021年8月30日
最近浏览更多
pangzhihui LV12
4月16日
liuxing_aa
4月15日
暂无贡献等级
wananall LV13
3月13日
laishaofe LV7
1月16日
shanmian
1月9日
暂无贡献等级
Liang朝伟 LV1
1月6日
asddwh LV12
2023年12月29日
17693282606 LV11
2023年12月20日
weilaizhisheng LV21
2023年12月5日
阿凡达 LV9
2023年11月11日