package com.friend.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import com.friend.common.DB;
import com.friend.entity.User;
public class UserDao {
private static DB connection = null;
public UserDao() {
connection = new DB();
}
/**
* 验证用户名和密码
* @param username,psw
* @return
*/
public boolean checkUser(String username, String psw)
{
ResultSet rs;
String strSql = (new StringBuffer()).append("select * from members where ID='").append(username).append("' and psw='").append(psw).append("'").toString();
rs = connection.executeQuery(strSql);
try
{
if(rs.next())
return true;
}
catch(SQLException ex)
{
ex.printStackTrace();
}
return false;
}
/**
* 获取用户数据信息
* @param ID
* @return
*/
public User getUserInfo(String ID)
{
String strSql = (new StringBuffer()).append("select * from members where ID='").append(ID).append("';").toString();
ResultSet rs = connection.executeQuery(strSql) ;
User user = new User();
try
{
if(rs.next())
{
user.setPsw(rs.getString("psw"));
user.setSex(rs.getString("sex"));
user.setEmail(rs.getString("email"));
user.setBirthyear(rs.getInt("birthyear"));
user.setBirthmonth(rs.getInt("birthmonth"));
user.setBirthday(rs.getInt("birthday"));
user.setScore(rs.getInt("score"));
user.setGrade(rs.getString("grade"));
user.setLasTime(rs.getString("lasttime"));
user.setRegistTime(rs.getString("registtime"));
user.setRealName(rs.getString("realname"));
user.setProvince(rs.getString("province"));
user.setCity(rs.getString("city"));
user.setMobile(rs.getString("mobile"));
user.setAddress(rs.getString("address"));
user.setHeight(rs.getInt("height"));
user.setWeight(rs.getInt("weight"));
user.setHobby(rs.getString("hobby"));
user.setWorkedat(rs.getString("workedat"));
user.setPost(rs.getString("post"));
user.setLookingfor(rs.getString("lookingfor"));
user.setIntroduction(rs.getString("introduction"));
user.setLocked(rs.getString("locked"));
user.setOpen(rs.getString("open"));
}
}catch(SQLException ex) {
ex.printStackTrace();
}
return user;
}
/**
* 获取用户列表
* @param ID
* @return
*/
public Vector getUserList()
{
String sql = "select * from members order by registtime desc";
Vector userList = new Vector();
try
{
ResultSet rs = connection.executeQuery(sql);
while(rs.next()){
User user = new User();
user.setID(rs.getString("ID"));
user.setSex(rs.getString("sex"));
user.setGrade(rs.getString("grade"));
user.setRegistTime(rs.getString("registtime"));
user.setOpen(rs.getString("open"));
user.setLocked(rs.getString("locked"));
userList.add(user);
}
}
catch(SQLException ex1) { }
return userList;
}
/**
* 添加用户
* @param ID
* @return
*/
public boolean Insert(String ID, String psw, String sex, int birthyear, int birthmonth, int birthday,
String email, String realname, String province, String city, String mobile, String address, int height,
int weight, String workedat, String post, String hobby, String lookingfor, String introduction, int score,
String open)
throws Exception
{
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date currentTime = new java.util.Date();
String time = formatter.format(currentTime);
String strSql = (new StringBuffer()).append("insert into members set ID='").append(ID).
append("',psw='").append(psw).append("',sex='")
.append(sex).append("',birthyear=").append(birthyear)
.append(",birthmonth=").append(birthmonth).append(",birthday=")
.append(birthday).append(",email='").append(email).append("',realname='")
.append(realname).append("',province='").append(province).append("',city='")
.append(city).append("',mobile='").append(mobile).append("',address='")
.append(address).append("',height=").append(height).append(",weight=").append(weight)
.append(",workedat='").append(workedat).append("',post='").append(post).append("',hobby='")
.append(hobby).append("',lookingfor='").append(lookingfor).append("',introduction='")
.append(introduction).append("',grade='\u666E\u901A\u4F1A\u5458',score=").append(score)
.append(",registtime='").append(time).append("',locked='false',open='").append(open).append("';").toString();
return connection.executeUpdate(strSql);
}
/**
* 获取用户等级
* @param name
* @return
*/
public String checkGrade(String name)
{
String grade="";
String strSql = (new StringBuffer()).append("select * from members where ID='").append(name).append("'").toString();
ResultSet rs = connection.executeQuery(strSql);
try
{
if(rs.next())
grade = rs.getString("grade");
}
catch(SQLException ex)
{
ex.printStackTrace();
}
return grade;
}
/**
* 等级更新
* @param name
* @param usergrade
* @return
*/
public boolean setGrade(String name, String usergrade)
{
String strSql = (new StringBuffer()).append("update members set grade='").append(usergrade).append("' where ID='").append(name).append("'").toString();
return connection.executeUpdate(strSql);
}
/**
* 获取用户的积分
* @param name
* @return
*/
public int getScore(String name)
{
int score = 0;
String strSql = (new StringBuffer()).append("select * from members where ID='").append(name).append("'").toString();
ResultSet rs = connection.executeQuery(strSql);
try
{
if(rs.next())
score = rs.getInt("score");
}
catch(SQLException ex)
{
ex.printStackTrace();
}
return score;
}
/**
* 设置用户的积分
* @param name
* @param n
*/
public void addScore(String name, int n)
{
int score = getScore(name) + n;
String strSql = (new StringBuffer()).append("update members set lasttime=null, score=").append(score).append(" where ID='").append(name).append("'").toString();
connection.executeUpdate(strSql);
}
/**
* 获取新进会员
* @param count
*/
public Vector getLastMember(int count)
{
String sql = "select * from members order by registtime desc;";
ResultSet rs = connection.executeQuery(sql);
Vector lastmembers = new Vector();
int i = 0;
try
{
rs.absolute(1);
do
{
if(i >= count || rs.isAfterLast())
break;
User user = new User();
user.setID(rs.getString("ID"));
user.setRegistTime(r
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
交友网站 JSP+Mysql (270个子文件)
39-1.bmp 2KB
41-1.bmp 632B
50-1.bmp 632B
42-1.bmp 632B
45-1.bmp 632B
4-1.bmp 632B
45-2.bmp 632B
52-1.bmp 632B
41-1.bmp 632B
44-2.bmp 624B
44-1.bmp 624B
51-1.bmp 612B
5-1.bmp 608B
47-1.bmp 604B
40-1.bmp 600B
53-1.bmp 600B
40-1.bmp 600B
48-1.bmp 600B
43-2.bmp 600B
49-1.bmp 600B
43-1.bmp 588B
46-1.bmp 588B
UserDao.class 8KB
User.class 6KB
MessageDao.class 6KB
PicDao.class 4KB
DefaultServlet.class 3KB
JspCalendar.class 3KB
EditUserInfo.class 3KB
DB.class 3KB
RegisterServlet.class 3KB
ImageEnsure.class 2KB
Message.class 2KB
LoginServlet.class 2KB
FriendDao.class 2KB
WriteServlet.class 2KB
DeletePicServlet.class 2KB
AddPicServlet.class 2KB
AddFriendServlet.class 2KB
EditManagerServlet.class 1KB
DeleteMessageServlet.class 1KB
DeleteUserServlet.class 1KB
PageShow.class 1KB
Encoding.class 1KB
DBTest.class 962B
GoodFriends.class 957B
Pic.class 940B
Constant.class 774B
.classpath 1KB
org.eclipse.wst.jsdt.ui.superType.container 49B
menu.css 2KB
style.css 2KB
style.css 2KB
Thumbs.db 93KB
Thumbs.db 90KB
xwork-validator-1.0.3.dtd 829B
bottom.gif 50KB
bottom.gif 50KB
show.gif 38KB
top.gif 29KB
top.gif 29KB
member.gif 8KB
member.gif 8KB
member_235.gif 8KB
member_235.gif 8KB
item_01.gif 5KB
item_01.gif 5KB
item_02.gif 4KB
item_02.gif 4KB
item_06.gif 4KB
item_06.gif 4KB
item_03.gif 4KB
item_03.gif 4KB
item_07.gif 4KB
item_07.gif 4KB
item_04.gif 3KB
item_04.gif 3KB
item_05.gif 3KB
item_05.gif 3KB
google.gif 3KB
google.gif 3KB
footer_bg.gif 1KB
footer_bg.gif 1KB
bg_r.gif 1KB
bg_r.gif 1KB
bt_09.gif 1KB
bt_09.gif 1KB
bt_11.gif 1KB
bt_11.gif 1KB
bt_10.gif 1KB
bt_10.gif 1KB
bt_03.gif 995B
bt_03.gif 995B
bt_01.gif 965B
bt_01.gif 965B
bt_06.gif 961B
bt_06.gif 961B
bt_07.gif 952B
bt_07.gif 952B
bt_05.gif 936B
共 270 条
- 1
- 2
- 3
∞+1
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页