⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.java

📁 基于JAVA的一个注册系统 最初只是为了公司做演示使用
💻 JAVA
字号:
package net.yefei.cmn.user;
import net.yefei.cmn.db.*;
import java.io.*;
import java.util.*;
import java.sql.*;
/*
* @author ye fei
* @version 1.00, 2003/04/15
* @copyright www.studyjava.com
*/
public class User {

private UserData data;

private DataBase dbConn=null;

  /*
   * Construct a new User
   *
   */
  public User() {

     dbConn=new DataBase();
     //ListUserInfo();
  }
  /*
   * Insert User Info
   */
public int InsertUserInfo(String password,String UserName,String UserSex,String UserEmail){
      int i=0;
      int id=0;
      java.sql.Statement stmt=null;
      /*
       *Count temp to confirm the userid is unique, temp is the userid.
       */
      int temp=1;
      /*
       *Specific the sql for querry.
       */

      String sql = "select userid from userinfo_bean";
      try{
        /*
         *Return result to rs
         */
        stmt=dbConn.getConnection().createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      while(rs.next()){
              id=rs.getInt("userid");
              temp=id+1;
      }
      /*
       *close the rs
       */
      rs.close();
      }catch(SQLException E){
        /*
         *catch nothing
         */
      }
      try{
        /*
         *Specific the insert_sql for insert @parm
         */
      String insert_sql = "insert into userinfo_bean(userid,password,UserName,UserSex,UserEmail,regdate,lasedate) values("+
      temp+",'"+password+"','"+UserName+"','"+UserSex+"','"+UserEmail+"','now','now')";

      i=stmt.executeUpdate(insert_sql);
         dbConn.close();
         }
         catch( Exception sqle )
         {
         /*
         *catch the Exception and printStackTrace
         */
             sqle.printStackTrace();
         }
         /*
          *return an integer,if insert data successfully,its value will be 1.
          */
          return i;
         }

  public int DeleteUserInfo(int[]userid){
               int i=0;

               int j=userid.length;
               try
       {
         while (j >= 1) {
           j = j - 1;
           String DELETE_USER_BY_NAME =
               "delete from userinfo_bean where userid=" + userid[j];
           i = dbConn.getConnection().createStatement().executeUpdate(
               DELETE_USER_BY_NAME);
           dbConn.close();
         }
          }
         catch (Exception sqle) {
           /*
            *catch the Exception and printStackTrace
            */
           sqle.printStackTrace();
           dbConn.close();
         }

                /*
                   *return an integer,if insert data successfully,its value will be 1.
                   */
                   return i;
                  }


  public int ModifyUserInfo(String UserName,String userid,String password,String UserSex,String UserEmail){
      int i=0;
      try{
        String UPDATE_USER_BY_NAME =
            "update userinfo_bean set "
            +"UserName='"+UserName+"',userid='"+userid+"',"+"password='"+password+"',"
            +"UserSex='"+UserSex+"',"+"UserEmail='"+UserEmail+"'";
        i = dbConn.getConnection().createStatement().executeUpdate(
        UPDATE_USER_BY_NAME);
        dbConn.close();
      }
      catch (Exception sqle) {
        /*
         *catch the Exception and printStackTrace
         */
         sqle.printStackTrace();
         dbConn.close();
      }

         /*
         *return an integer,if insert data successfully,its value will be 1.
         */
        return i;
  }

  /*
   *List User Info.
   *The return value is a Vector.
   */
public UserData ListUserInfo(int id){
  /*
   *Define an Userdata.
   */
UserData ndata=new UserData();
try
     {
  /*
   *Specific the sql for querry.
   */
  String sql = "select * from userinfo_bean";
  /*
   *Return result to rs
   */
  ResultSet rs = dbConn.getConnection().createStatement().executeQuery(sql);



  /*
       *Set user info.
       */
       while (rs.next()) {
         ndata.setUserId(rs.getInt("userid"));
         ndata.setPassword(rs.getString("password"));
         ndata.setUserName(rs.getString("UserName"));
         ndata.setUserSex(rs.getString("UserSex"));
         ndata.setUserEmail(rs.getString("UserEmail"));
         ndata.setRegDate(rs.getDate("regdate"));
         ndata.setLastDate(rs.getDate("lasedate"));
       }
       rs.close();
       dbConn.close();
     } catch( Exception sqle )
     {
     /*
      *catch the Exception and printStackTrace
      */
         sqle.printStackTrace();
         dbConn.close();
     }
     /*
     *Return an userdata Vector.
     */
         return ndata;
}



      /*
       *List User Info.
       *The return value is a Vector.
       */
  public Vector ListUserInfo(){
    /*
     * An important static vector,stored by userlistaction.java
     * and invoked by userlist.jsp
     */
     Vector vdata = new Vector();

    try
         {
      /*
       *Specific the sql for querry.
       */
      String sql = "select * from userinfo_bean";
      /*
       *Return result to rs
       */
      ResultSet rs = dbConn.getConnection().createStatement().executeQuery(sql);

     /*
      *Define an Userdata.
      */

      /*
           *Set user info.
           */

           while (rs.next()) {
             UserData ndata=new UserData();
             ndata.setUserId(rs.getInt("userid"));
             ndata.setPassword(rs.getString("password"));
             ndata.setUserName(rs.getString("UserName"));
             ndata.setUserSex(rs.getString("UserSex"));
             ndata.setUserEmail(rs.getString("UserEmail"));
             ndata.setRegDate(rs.getDate("regdate"));
             ndata.setLastDate(rs.getDate("lasedate"));
             vdata.add(ndata);
           }
           rs.close();
           dbConn.close();
         } catch( Exception sqle )
         {
         /*
          *catch the Exception and printStackTrace
          */
             sqle.printStackTrace();
         }
         /*
         *Return an userdata Vector.
         */
             return vdata;
  }

  public Vector getvv() {
  /*
   * An important static vector,stored by userlistaction.java
   * and invoked by userlist.jsp
   */
    Vector vv=null;
    try{
    vv=ListUserInfo();
    }
    catch( Exception sqle ){
         }
      return vv;
  }


  /*
   *Test the fuctions.
   */
public static void main(String[] argvs){
       User w=new User();
       w.ListUserInfo();
       //w.InsertUserInfo("ss","ss","aa2","3d");
         }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -