用户注册



邮箱:

密码:

用户登录


邮箱:

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

发表随想


还能输入:200字

云代码会员    -  云代码空间

——

库存管理

2014-07-07|1288阅||

摘要:库存管理

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();
  
 }

 

}

顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 云代码会员
    • 等级: 初级程序员
    • 积分: 0
    • 代码: 2 个
    • 文章: 1 篇
    • 随想: 0 条
    • 访问: 1 次
    • 关注

    人气文章

    人气代码

    最新提问

      站长推荐