Make the input on the page into input variables for a stored procedure which then runs a select statement based on those variables. Dynamically create the where clause using those variables. This can get quite complex depending on how many inputs you allow on the form and whether they are all And conditions or Or conditions or a combination. One of ours has 30 variables and a combination of and, or in and full text search. It's also 15 or 16 pages long. We take care of pagination through our client interface (.NET based, but I'm sure you can do something similar in Java) and we sometimes limit the total number of records which can be returned to save from returning too many records in the SELECT Statements.
A simplified sample of our search from a web form stored procedure is below:
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
Create PROCEDURE USP_SELECT_Search (@AirState as nvarchar(2) = NULL,
@AirCity as nvarchar(50) = NULL)
AS
Declare @SQLWhere nvarchar(500)
Set @SQLWhere = ''
---Build Query
If @AirState <> '' and @AirState is not Null
Set @SQLWhere = 'State = "' + @AirState+'"'
If @AirCity <>'' and @AirCity is not Null
begin
If @SQLWhere <> ''
Set @SQLWhere =@SQLWhere+ ' and City = "' +@AirCity+'"'
else
Set @SQLWhere = 'City = "' +@AirCity+'"'
End
If @SQLWhere <> ''
Begin
Set @SQLWhere = 'Where ' + @SQLWhere
exec("SELECT AirportName, Airport.AirportID, City, State, AirportType, FacilityUse, Country, SATSID
FROM Airport LEFT OUTER JOIN
SATSAirports ON SATSAirports.AirportID = Airport.AirportID " + @SQLWhere)
End
ELse
Begin
SELECT AirportName, Airport.AirportID, City, State, AirportType, FacilityUse, Country, SATSID
FROM Airport LEFT OUTER JOIN
SATSAirports ON SATSAirports.AirportID = Airport.AirportID
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO