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

📄 userlist.java

📁 一个关于商业的网站
💻 JAVA
字号:
package com.everstar.usermanage;

import java.sql.*;
import java.io.*;
import java.util.ArrayList;
import com.everstar.database.*;

public class UserList {

	//private static final String DELETE_USER_BY_ID = "delete from JIVEUSER where Userid=?";
	//private static final String DELETE_USER_BY_NAME = "delete from JIVEUSER where Username=?";
	private static final String LOAD_USER_ID = "select userid from JIVEUSER order by userid";
	private static final String USER_COUNT = "select count(*) from JIVEUSER";
	private Database dbConn;

	public UserList(Database dbConn)
	{
		this.dbConn = dbConn;
	}

	public  User createUser(String userName,String trueName,String password,String email,String Telephone,String Address)
	{
		return new User(userName,trueName,password,email,Telephone,Address, this,dbConn);
	}

	public User getUser(int userID)
	{
		return new User(userID,  this,dbConn);

	}

	public User getUser(String userName)
	{
		return new User(userName,  this,dbConn);
	}

	public  void removeUser(int userID)
	{
	   deletedb(userID);
	}

	public  void removeUser(String name)
	{
	   deletedb(name);
	}

	public  void removeUser(User theuser)
	{
	   deletedb(theuser.getUserID());
	}

	//return a Userid list
	public int[] Users()
	{
        ArrayList tempArrayList = new ArrayList();
        try
        {
        	ResultSet rs =dbConn.select(LOAD_USER_ID);
        	while(rs.next())
        	{
	        	tempArrayList.add(new Integer(rs.getInt(1)));
        	}
        	rs.close();
        	dbConn.close();
		}
        catch( Exception e )
        {
            e.printStackTrace();
        }

		int[] listUserArray = new int[tempArrayList.size()];
		for (int i = 0;i < listUserArray.length; i++  )
		{
			listUserArray[i] = ((Integer)tempArrayList.get(i)).intValue();
		}
		return listUserArray;

	}

	// get Userid from table User index length = leng
	public int[] Users(int fromindex,int leng)
	{

        ArrayList tempArrayList = new ArrayList();
        try
        {
        	ResultSet rs =dbConn.select(LOAD_USER_ID);
        	for (int i=0;i<fromindex;i++ )
        	{
        	rs.next();
        	}
        	for (int i=0;i<leng;i++ )
        	{
	        	if (rs.next())
	        	{
	        	tempArrayList.add(new Integer(rs.getInt(1)));
	        	}
        	}
        	rs.close();
        	dbConn.close();
		}
        catch( Exception e )
        {
            e.printStackTrace();
        }

		int[] listUserArray = new int[tempArrayList.size()];
		for (int i = 0;i < listUserArray.length; i++  )
		{
			listUserArray[i] = ((Integer)tempArrayList.get(i)).intValue();
		}
		return listUserArray;


	}


	// get User count

	public int getUserCount()
	{
        int temp = 0;
        try
        {
        	ResultSet rs =dbConn.select(USER_COUNT);
        	rs.next();
        	temp = rs.getInt(1);
        	rs.close();
        	dbConn.close();

		}
        catch( Exception e )
        {
            e.printStackTrace();
        }

		return temp;
	}

	//delete from Userid
	private void deletedb(int ID)
	{
        try
        {
		 	String DELETE_USER_BY_ID = "delete from JIVEUSER where Userid="+ID;
        	int i=dbConn.delete(DELETE_USER_BY_ID);
		}
        catch( Exception sqle )
        {
            sqle.printStackTrace();
        }
	}

	//delete from Username
	private void deletedb(String name)
	{
        try
        {
		 	String DELETE_USER_BY_NAME = "delete from JIVEUSER where username='"+name+"'";
        	int i=dbConn.delete(DELETE_USER_BY_NAME);

		}
        catch( Exception sqle )
        {
            sqle.printStackTrace();
        }
	}


}

⌨️ 快捷键说明

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