package com.vote.service; import java.net.InetAddress; import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; public class VoteService { public String showUser() throws SQLException { String sql = "select * from vote_user"; StringBuffer result = new StringBuffer(); ResultSet rs = DBService.getConnection().createStatement().executeQuery(sql); while(rs.next()) { result.append("{\"uid\":\"").append(rs.getString("uid")).append("\","); result.append("\"username\":\"").append(rs.getString("username")).append("\"},"); } return result.deleteCharAt(result.length() - 1).toString(); } public boolean vote(String uid) throws UnknownHostException, SQLException { InetAddress addr = InetAddress.getLocalHost(); String ip=addr.getHostAddress().toString(); //获得本机IP String findSql = "select ip from vote_vote where ip = '" + ip + "'"; ResultSet rs = DBService.getConnection().createStatement().executeQuery(findSql); if(rs.next()) { return false; } else { String insertSql = "insert into vote_vote(uid, ip, votedate) values ('" + uid + "','" + ip + "','" + new java.sql.Date(System.currentTimeMillis()) + "')"; int res = DBService.getConnection().createStatement().executeUpdate(insertSql); if(res > 0) return true; } return false; } }
最近下载更多
梦幻瞳 LV1
2022年11月24日
hhhccc LV1
2022年11月6日
wubinbin LV11
2022年10月24日
lhlh123456 LV1
2022年6月17日
744083587 LV1
2022年6月13日
我是阿拉伯王子 LV1
2022年4月20日
起个名字好难起 LV1
2021年12月20日
3089559272 LV11
2021年12月17日
tracy-wang LV1
2021年10月30日
LELLsCORT LV1
2021年9月14日
最近浏览更多
wananall LV13
3月13日
admin_z LV22
1月29日
laishaofe LV7
1月16日
shanmian
1月9日
暂无贡献等级
嗯嗯嗯嗯嗯嗯2528
2023年11月29日
暂无贡献等级
pangzhihui LV12
2023年11月16日
阿凡达 LV9
2023年11月12日
ftc1314 LV12
2023年11月2日
hj1172788262 LV5
2023年10月25日
hhhhyp
2023年10月16日
暂无贡献等级