/* -- ' Copyright by Erica Andrews aka CyLiKoN JeZuZ aka Li'L CJ, ' January 2000. No one is permitted to implement this JavaBean ' or any portion of it on their site without the express written consent ' of the author (cylikon@hotmail.com - ./IcedPinky/). ' All rights reserved. ' This Bean was hand-coded in Java by Erica Andrews on Jan. 11, 2000 ' The bean works as a stored procedure for searching sites in ' my database by creating setter methods, which are set remotely using the ' setProperty in a JSP page. The parameter "searchword" sets the value in ' the "LIKE % %" clause, which determines the sites to ' retrieve from the database. The "limit1" and "limit2" parameters are also ' controlled through the JSP page and are used to control the number of ' results shown per page. The getGenericSearch() method then returns ' the RAW, unformatted ResultSet of the query, which can then be formatted ' into links, tables, forms, etc by the same JSP page. The Bean uses the ' gweMySQLJDBC 0.9.2 driver and MySQL 3.22.9 for database connectivity. -- */ package yahoo; import java.io.*; import java.util.*; import java.sql.*; import gwe.sql.*; public class Search { /* This is the parameter for the search term submitted from the JSP page */ private String searchword; /* variables to control the LIMIT statement in the MySQL Query...to limit the number of results shown per page */ private String limit1; private String limit2; /* creating Set and Get methods for variables "searchword","limit1", and "limit2" */ public Search() { searchword = null; limit1 = null; limit2 = null; } public void setSearchword( String word ) { searchword = word; } public String getSearchword() { return searchword; } public void setLimit1( String lim1 ) { limit1 = lim1; } public String getLimit1() { return limit1; } public void setLimit2( String lim2 ) { limit2 = lim2; } public String getLimit2() { return limit2; } /* -- Creating a method GenericSearchLimited which will return 20 results per page--- */ public ResultSet getGenericSearchLimited() throws SQLException, ClassNotFoundException { Class.forName ("gwe.sql.gweMysqlDriver"); Connection conn = DriverManager.getConnection ("jdbc:mysql://:3306/siteindex2","MySecret","MySecret"); Statement stmt = conn.createStatement (); ResultSet results = stmt.executeQuery ("SELECT DISTINCT thesites.url,keywords.thetitle,thesites.itsgroup,thesites.thedate FROM keywords,thesites WHERE keyword LIKE '%"+(getSearchword())+"%' AND thesites.url=keywords.url LIMIT "+(getLimit1())+","+(getLimit2()) ); return (results); } // --- ending method GenericSearchLimited /* -- Creating a method GenericSearch which will return the TOTAL results found in the database...for counting purposes, and also in case I decide later that I want to show all results on one page --- */ public ResultSet getGenericSearch() throws SQLException, ClassNotFoundException { Class.forName ("gwe.sql.gweMysqlDriver"); Connection conn = DriverManager.getConnection ("jdbc:mysql://:3306/siteindex2","MySecret","MySecret"); Statement stmt = conn.createStatement (); ResultSet results = stmt.executeQuery ("SELECT DISTINCT thesites.url,keywords.thetitle,thesites.itsgroup,thesites.thedate FROM keywords,thesites WHERE keyword LIKE '%"+(getSearchword())+"%' AND thesites.url=keywords.url"); // --LIMIT Removed return (results); } // --- ending method GenericSearch } // - End of Class Search