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

📄 libraryobject.java

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

/** 
 * This bean contains all library object wide code.
 * Note that it is an abstract class.
 * @author  dms
 * @version 
 */
public abstract class LibraryObject {

	protected static int TRANSACTION_RETRIES = 5;

    protected DBWrapper db;
    protected ResultSet mr; 
    protected Hashtable errors;
   
    public LibraryObject() {
    	errors = new Hashtable();	
    }
   
    /**
    * Accepts an open database connection for the bean to use.
    *
    * @param <b>DBWrapper</b> - DBWrapper object
    */
    public void setConnection(DBWrapper wrap) {
      db = wrap;
    }
    
    /**
     * Checks to see if a connection is present, if not, then
     * it creates one.
     *
     */
    public void ensureconnection() {
        
        if (db == null) {
            db = new DBWrapper();
            db.openDatabase();
        }
    }
    
    /**
    * <p>Sets the bean to the next object found.  This
    * routine can only be called after a call has been made to
    * a descendant getXXXX() routine.</p>
    * 
    * 
    *    
    * @return <b>boolean</b> - true if next object found, false if no more object
    */
    public boolean getNext() {
      
	  try {
	  	
	  	if (mr != null) {
		    if (mr.next()) {
		      setVariables(mr);
		      return true;
		    }
		    else
		      return false;
		     }
	    else
	        return false;
	  }
	  catch (SQLException e) {
	    System.out.println("Get Next Threw Exception: " + e.toString());
	    return false;
	  }
	 
    }
    
    /**
    * sets field variables based on record from resultset
    * @param r   Resultset
    */
    protected void setVariables(ResultSet r) throws SQLException {
    }   
    
    /**
	* Gets a field specific error message
	* @param s  the field name
	* @return String containing error message
	*/
    public String getErrorMsg(String s) {
        String errorMsg = (String)errors.get(s.trim());
        return (errorMsg == null) ? "":errorMsg;
    }
    
    /**
    * Sets a field specific error message
    * @param key  the field name
    * @param msg  the message
    */
    public void setErrors(String key, String msg) {errors.put(key,msg);} 
      
    /**
    * Clears all field specific error validation messages
    */
    public void clearErrors() {errors = new Hashtable();}

}

⌨️ 快捷键说明

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