用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

kucuguanli

2014-07-07 作者: 云代码会员举报

[c]代码库

package com.CsmsCode.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.CsmsCode.DB.DBConnection;
import com.CsmsCode.VO.UserVo;

public class UserDao {
	
	
	public int login(String userLogin,String userPwd) throws ClassNotFoundException, SQLException
	{
		
		
		StringBuffer strSql=new StringBuffer();
		strSql.append("select count(*) from users where userLogin='"+userLogin+"' and userPwd='"+userPwd+"'");
		
		int r=0;
		DBConnection db=new DBConnection();
		Connection conn=db.getConnection();
		
		PreparedStatement pst=conn.prepareStatement(strSql.toString());
		
		ResultSet rs= pst.executeQuery();
		
		while (rs.next())
		{
			r=rs.getInt("count(*)");
		}
		
		return r;
		
	}
	
	public List<UserVo> getUsers(String userLogin,String userName) throws ClassNotFoundException, SQLException
	{
		StringBuffer strSql=new StringBuffer();
		
		strSql.append("select * from users where 1=1 ");
		
		if (!userLogin.equals(""))
		{
			
			strSql.append(" and userLogin='"+userLogin+"' ");
		}
		
		if (!userName.equals(""))
		{
			
			strSql.append(" and userName='"+userName+"'");
		}
		
		DBConnection db=new DBConnection();
		Connection conn=db.getConnection();
		PreparedStatement pst=conn.prepareStatement(strSql.toString());
		ResultSet rs= pst.executeQuery();
		
	    List<UserVo> users=new ArrayList<UserVo>();
	    
	    while (rs.next())
	    {
	    	UserVo myUser=new UserVo();
	    	myUser.setFlag(rs.getInt("flag"));
	    	myUser.setUserLogin(rs.getString("userLogin"));
	    	myUser.setUserName(rs.getString("userName"));
	    	myUser.setUserNote(rs.getString("userNote"));
	    	myUser.setUserPwd(rs.getString("userPwd"));
	    	users.add(myUser);
	    	
	    }
	    
	    return users;
		 
		
	}
	
	
	public void addUser(UserVo uservo) throws ClassNotFoundException, SQLException
	{
		StringBuffer strSql=new StringBuffer();
		strSql.append("insert into users values ('"+uservo.getUserLogin()+"','"+uservo.getUserName()+"','"+uservo.getUserNote()+"','"+uservo.getUserPwd()+"','0)");
		
		DBConnection db=new DBConnection();
		Connection conn=db.getConnection();
		
		PreparedStatement pst=conn.prepareStatement(strSql.toString());
		pst.executeUpdate();
		
	}
	
	public void updateUser(UserVo uservo) throws ClassNotFoundException, SQLException
	{
		StringBuffer strSql=new StringBuffer();
		strSql.append("update users set userName='"+uservo.getUserName()+"',userPwd='"+uservo.getUserPwd()+"',userNote='"+uservo.getUserNote()+"'where userLogin='"+uservo.getUserLogin()+"'");
		
		DBConnection db=new DBConnection();
		Connection conn=db.getConnection();
		
		PreparedStatement pst=conn.prepareStatement(strSql.toString());
		pst.executeUpdate();
		
	}
	
	public void delUser(String userLogin) throws ClassNotFoundException, SQLException
	{
		StringBuffer strSql=new StringBuffer();
		strSql.append("delete from users where userLogin='"+userLogin+"' ");
		
		DBConnection db=new DBConnection();
		Connection conn=db.getConnection();
		
		PreparedStatement pst=conn.prepareStatement(strSql.toString());
		pst.executeUpdate();
		
	}

	

}

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...