[C] 库存管理 →→→→→进入此内容的聊天室

来自 , 2021-03-21, 写在 C, 查看 136 次.
URL http://www.code666.cn/view/b3f61131
  1. package com.CsmsCode.Dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. import com.CsmsCode.DB.DBConnection;
  11. import com.CsmsCode.VO.UserVo;
  12.  
  13. public class UserDao {
  14.        
  15.        
  16.         public int login(String userLogin,String userPwd) throws ClassNotFoundException, SQLException
  17.         {
  18.                
  19.                
  20.                 StringBuffer strSql=new StringBuffer();
  21.                 strSql.append("select count(*) from users where userLogin='"+userLogin+"' and userPwd='"+userPwd+"'");
  22.                
  23.                 int r=0;
  24.                 DBConnection db=new DBConnection();
  25.                 Connection conn=db.getConnection();
  26.                
  27.                 PreparedStatement pst=conn.prepareStatement(strSql.toString());
  28.                
  29.                 ResultSet rs= pst.executeQuery();
  30.                
  31.                 while (rs.next())
  32.                 {
  33.                         r=rs.getInt("count(*)");
  34.                 }
  35.                
  36.                 return r;
  37.                
  38.         }
  39.        
  40.         public List<UserVo> getUsers(String userLogin,String userName) throws ClassNotFoundException, SQLException
  41.         {
  42.                 StringBuffer strSql=new StringBuffer();
  43.                
  44.                 strSql.append("select * from users where 1=1 ");
  45.                
  46.                 if (!userLogin.equals(""))
  47.                 {
  48.                        
  49.                         strSql.append(" and userLogin='"+userLogin+"' ");
  50.                 }
  51.                
  52.                 if (!userName.equals(""))
  53.                 {
  54.                        
  55.                         strSql.append(" and userName='"+userName+"'");
  56.                 }
  57.                
  58.                 DBConnection db=new DBConnection();
  59.                 Connection conn=db.getConnection();
  60.                 PreparedStatement pst=conn.prepareStatement(strSql.toString());
  61.                 ResultSet rs= pst.executeQuery();
  62.                
  63.             List<UserVo> users=new ArrayList<UserVo>();
  64.            
  65.             while (rs.next())
  66.             {
  67.                 UserVo myUser=new UserVo();
  68.                 myUser.setFlag(rs.getInt("flag"));
  69.                 myUser.setUserLogin(rs.getString("userLogin"));
  70.                 myUser.setUserName(rs.getString("userName"));
  71.                 myUser.setUserNote(rs.getString("userNote"));
  72.                 myUser.setUserPwd(rs.getString("userPwd"));
  73.                 users.add(myUser);
  74.                
  75.             }
  76.            
  77.             return users;
  78.                  
  79.                
  80.         }
  81.        
  82.        
  83.         public void addUser(UserVo uservo) throws ClassNotFoundException, SQLException
  84.         {
  85.                 StringBuffer strSql=new StringBuffer();
  86.                 strSql.append("insert into users values ('"+uservo.getUserLogin()+"','"+uservo.getUserName()+"','"+uservo.getUserNote()+"','"+uservo.getUserPwd()+"','0)");
  87.                
  88.                 DBConnection db=new DBConnection();
  89.                 Connection conn=db.getConnection();
  90.                
  91.                 PreparedStatement pst=conn.prepareStatement(strSql.toString());
  92.                 pst.executeUpdate();
  93.                
  94.         }
  95.        
  96.         public void updateUser(UserVo uservo) throws ClassNotFoundException, SQLException
  97.         {
  98.                 StringBuffer strSql=new StringBuffer();
  99.                 strSql.append("update users set userName='"+uservo.getUserName()+"',userPwd='"+uservo.getUserPwd()+"',userNote='"+uservo.getUserNote()+"'where userLogin='"+uservo.getUserLogin()+"'");
  100.                
  101.                 DBConnection db=new DBConnection();
  102.                 Connection conn=db.getConnection();
  103.                
  104.                 PreparedStatement pst=conn.prepareStatement(strSql.toString());
  105.                 pst.executeUpdate();
  106.                
  107.         }
  108.        
  109.         public void delUser(String userLogin) throws ClassNotFoundException, SQLException
  110.         {
  111.                 StringBuffer strSql=new StringBuffer();
  112.                 strSql.append("delete from users where userLogin='"+userLogin+"' ");
  113.                
  114.                 DBConnection db=new DBConnection();
  115.                 Connection conn=db.getConnection();
  116.                
  117.                 PreparedStatement pst=conn.prepareStatement(strSql.toString());
  118.                 pst.executeUpdate();
  119.                
  120.         }
  121.  
  122.        
  123.  
  124. }
  125.  

回复 "库存管理"

这儿你可以回复上面这条便签

captcha