check.java

来自「这是一个JSP网站程序」· Java 代码 · 共 161 行

JAVA
161
字号
package com.yibo.yiqu.db;
import java.util.*;
import java.sql.*;
/**
 * @author liuzhaofeng
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Check{
	
	Connection con;
	public static boolean checkisnull(String v){
		if((v.trim()==null)||(v.trim().equals(""))){
			return false;
		}else{
			return true;
		}
	}
	//check the name(管理员用户名)exist or not ,if not return false or return true
	public boolean namecheck(String name)
		throws Exception
	{
		boolean val;
		val = false;
		try
		{
			con = DataMYSQConnection.getConnectionbase();
		}		
		catch(Exception e1)
		{
			System.out.println("运行代号:Check 001");
		}
		String checknickname = "select * from super_user where name='"+name+"'";
		try
		{
			PreparedStatement pstmt = con.prepareStatement(checknickname);
			ResultSet rs= pstmt.executeQuery();
			if(rs.next())
			{
				val = true;
			}
			con.close();
		}catch(SQLException e)
		{
			System.out.println("运行代号:Check 002"+e);
		}
	    finally
        {
            try
            {
                if(con != null)
                   con.close();
            }
            catch(Exception exception1) 
            { 
            	System.out.println("运行代号:Check 003");
            }
        }
        return val;
	}
	//check pass exist or not 
	public boolean passcheck(int id,String pass)
		throws Exception
	{
		boolean val;
		val = false;
		try
		{
			con = DataMYSQConnection.getConnectionbase();
		}		
		catch(Exception e1)
		{
			System.out.println("运行代号:Check 004");
		}
		String checknickname = "select * from super_user where password='"+pass+"' and id="+id;
		try
		{
			PreparedStatement pstmt = con.prepareStatement(checknickname);
			ResultSet rs= pstmt.executeQuery();
			if(rs.next())
			{
				val = true;
			}
			con.close();
		}catch(SQLException e)
		{
			System.out.println("运行代号:Check 005"+e);
		}
	    finally
        {
            try
            {
                if(con != null)
                   con.close();
            }
            catch(Exception exception1) 
            { 
            	System.out.println("运行代号:Check 006");
            }
        }
        return val;
	}

	//管理员登陆
    public boolean logcheck(String name, String pass)
        throws Exception
    {
        boolean validate;
        validate = false;
        try
        {
            con = DataMYSQConnection.getConnectionbase();
        }
        catch(Exception e)
        {
            System.out.println("运行代号:Check 007");
        }
        String  signon = "select * from  super_user where name='"+name+"' and password='"+pass+"'";
        try
        {
            PreparedStatement pstmt = con.prepareStatement(signon);
            ResultSet rs = pstmt.executeQuery();
            if(rs.next())
            {
                validate = true;
            }
            con.close();
        }
        catch(SQLException e)
        {
            System.out.println("运行代号:Check 008"+e);
        }
        finally
        {
            try
            {
                if(con != null)
                    con.close();
            }
            catch(Exception exception1) 
            { 
            	System.out.println("运行代号:Check 009");
            }
        }
        return validate;
    }

    public static void main(String args[])
    {
    	Check u = new Check();
    	try{
    	System.out.println(u.namecheck("feng"));
    	}catch(Exception e)
    	{
    		System.out.print(e);	
    	}
    }
}

⌨️ 快捷键说明

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