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

📄 librarian.java

📁 图书馆检索系统
💻 JAVA
字号:
/*
 * Librarian.java
 *
 */
 
package library;
import java.util.*;
import java.sql.*;

/** 
 * This bean represents a librarian.
 * Class <code>Librarian</code> inherits
 * from class <code>SystemUser</code>.
 *
 * @author  dms
 * @version 1.0
 */
public class Librarian extends SystemUser {

	/**
	* Class constructor
	*/
	public Librarian() {super();}
	
	/**
	* Class constructor which retrieves specified librarian
	* @param ssn int containing ssn of the librarian to retrieve
	*/
    public Librarian(int ssn) {
    	super();
    	getLibrarian(ssn);	
    }
    
    /**
    * Retrieves the librarian specified by the ssn
    * @param ssn  int containing ssn of the librarian to retrieve
    * @return <b>boolean</b> - true if success, false if otherwise
    */
    public boolean getLibrarian(int ssn) {
      
      ensureconnection();
      
	  try {
	  	
	  	String sSQL = "SELECT * FROM Librarian WHERE ssn = " + ssn;
	  	ResultSet r = db.runQuery(sSQL);
	    if (r.next()) {
	      setVariables(r);
	      return true;
	    }
	    else
	      return false;
	     
	  }
	  catch (SQLException e) {
	    System.err.println("Exception occurred when trying to retrive librarian:\n" + e.toString());
	    return false;
	  }
	 
    }
    
    /**
    * To validate a librarian's id and password use this method
    * with the librarian's ssn and password.
    * @param ssn  int containing librarian's ssn
    * @param pass String containing password
    * @return boolean, true if validated, false if otherwise
    * @throws Exception
    */
    public boolean validate(int ssn, String pass) throws Exception {
    	
    	ensureconnection();

    	try {
    		
    		String sSQL = "SELECT * FROM Librarian WHERE ssn = " + ssn +
    					  " AND passwd = '" + pass + "'";
			System.err.println(sSQL);
			
			ResultSet r = db.runQuery(sSQL);
			
			if (r.next()) {
				setVariables(r);
				return true;	
			} else
				return false;    					  
    		
    	} catch (SQLException se) {
    		System.err.println("Exception encountered while attempting to validate Librarian\n" + se.toString());
    		throw se;
    	}
    	
    }
  
} 

⌨️ 快捷键说明

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