/* * Search.java * Author: Song Qian * Created on February 27, 2004, 10:23 PM */ package museum; import java.beans.*; import java.sql.*; import java.util.*; /** *

Title: Search.java

*

Description: Search for photo by id, name or description

*

Copyright: Copyright (c) 2004

*

Company: Song Qian

* @author Song Qian * @version 1.1 */ public class Search extends Object implements java.io.Serializable { private int pageSize = 15; // number of photos per page private int rowCount = 0; // total rows private int pageCount = 0; // total pages private int pageNumber; // page to be displayed private SQLManager database; private ResultSet rs; // SQL ResultSet private int searchKey = 0; // 1 for id, 2 for name, 3 for description private String keyWords = ""; /** Creates new Browse */ public Search() throws SQLException { database = new SQLManager(); } public ResultSet doSearch() throws SQLException { switch ( searchKey ) { case 1: rs = this.getID(); break; default: rs = this.getName(); break; } // rs.last(); // rowCount = rs.getRow(); // get row count // pageCount = ( rowCount + pageSize - 1 ) / pageSize; // rs.first(); // mover curser to first item return rs; } public ResultSet getID() throws SQLException { int iID = 0; try { iID = Integer.parseInt( keyWords ); } catch( NumberFormatException e ) { // do nothing, will search by id 0, result will be empty } rs = database.executeQuery( "SELECT * FROM ethnobot WHERE id=\"" + iID + "\"" ); return rs; } public ResultSet getName() throws SQLException { String strSearchKey = "name"; if ( searchKey == 3 ) strSearchKey = "description"; String sqlQuery = "SELECT * FROM ethnobot WHERE " + strSearchKey + " LIKE "; StringTokenizer searchWords = new StringTokenizer( keyWords ); int tokens = searchWords.countTokens(); if ( tokens > 1 ) { int tokenCount = 0; while ( searchWords.hasMoreTokens() && tokenCount