|
|
|
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.NamingException"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.sql.DataSource"%>
<%
PreparedStatement preStat =null;
PreparedStatement prestatcount = null;
Connection dbCon = null;
ResultSet rs = null;
String prodn = null;
String appr = "Y";
String selectStr = "select * from proddetails approved = ?";
String selectstr2 = "select * from proddetails where productname like ? and approved = ?";
String selectstr3 = "select * from proddetails where productname like ? and subcatid = ? and approved = ?";
String selectcount1 = "select count(*) as strcount from proddetails approved = ?";
String selectcount2 = "select count(*) as strcount from proddetails where productname like ? and approved = ?";
String selectcount3 = "select count(*) as strcount from proddetails where productname like ? and subcatid = ? and approved = ?";
ResultSet rscount = null;
String prodname = null;
String cuisine = null;
String cuisinestr = null;
String searchvalue = null;
String searchvalue1 = null;
String searchval = null;
try {
// javax.naming.Context initialContext = new javax.naming.InitialContext();
// javax.naming.Context envContext = (javax.naming.Context) initialContext.lookup("java:/comp/env");
// javax.sql.DataSource dataSource = (javax.sql.DataSource) envContext.lookup("jdbc/mssql");
Class.forName("com.mysql.jdbc.Driver").newInstance();
// dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/myrecipe","root","");
// dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3306/maheks_mahek","maheks","mahak");
// dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3309/maheks_mahek","root","");
//dbCon = DriverManager.getConnection("jdbc:mysql://localhost:3309/maheks_mahek","root","");
ServletContext ctx = getServletContext();
String url=ctx.getInitParameter("url");
String user=ctx.getInitParameter("user");
String pw=ctx.getInitParameter("password");
dbCon = DriverManager.getConnection(url,user,pw);
searchvalue = request.getParameter("searchstring");
cuisine = request.getParameter("cuisinename");
searchval = searchvalue;
//out.print("cuisine : " + cuisine);
searchvalue1=searchvalue;
if (searchvalue != null) {
searchvalue = "%" + searchvalue + "%";
} else {
searchvalue = "%" + " " + "%";
}
if (cuisine=="" || cuisine==null){
//out.println("in");
//out.println("null");
if (searchvalue1 == null){
searchvalue1="";
}
searchvalue = "%" + searchvalue1 + "%";
//out.println(searchvalue);
preStat = dbCon.prepareStatement(selectstr2);
prestatcount = dbCon.prepareStatement(selectcount2);
preStat.setString(1,searchvalue);
preStat.setString(2,appr);
prestatcount.setString(1,searchvalue);
prestatcount.setString(2,appr);
rs = preStat.executeQuery();
rscount = prestatcount.executeQuery();
} else {
//out.println("out");
//out.println(cuisine);
//out.println(searchvalue);
cuisinestr = "" + cuisine;
preStat = dbCon.prepareStatement(selectstr3);
prestatcount = dbCon.prepareStatement(selectcount3);
preStat.setString(1,searchvalue);
preStat.setString(2,cuisinestr);
preStat.setString(3,appr);
prestatcount.setString(1,searchvalue);
prestatcount.setString(2,cuisinestr);
prestatcount.setString(3,appr);
rs = preStat.executeQuery();
rscount = prestatcount.executeQuery();
}
// for paging
int noofelements = 2;
int count = 0;
int pageval = 0;
int startval =0;
int startval1 =0;
int pageend =0;
int startindx=0;
int endindx=0;
if (rscount.next()) {
count = rscount.getInt("strcount");
//out.println("| " + count + " | ");
}
if ((count % noofelements) == 0 ) {
pageval = count / noofelements;
//out.println("page1" + (count % noofelements));
} else {
pageval = (count / noofelements) + 1;
//out.println("page2" + pageval);
}
//out.println(count);
if (request.getParameter("startvalue") != null)
startval = Integer.parseInt(request.getParameter("startvalue"));
else
startval=0;
startval1=startval;
%>
<%
if (count!=0)
{
%>
|
navigate
<%
pageend=pageval-1;
startindx = startval1 - 2;
endindx = startval1 + 2;
//out.print(startindx+1);
//out.print(endindx+1);
if(startval1!= 0)
{
%>
« prev
<%
}
else
{
%>
<%
}
for (int j=0; j= startindx && j <= endindx)
{
//out.print(startval1);
if (j==startval1)
{
%>
<%=(j+1)%>
<%
}
else
{
%>
<%=(j+1)%>
<% }
}
}
if(startval1!= pageend)
{
%>
next »
<%
}
else
{
%>
<%
}
%>
|
<%
}
else
{
%>
|
<%
//out.print("No records found");
}
// for paging
%>
<%
// for paging
%>
|
| |
| |
| |
<%
if (startval==0) {
for (int i=1; i<=count; i++) {
if( i >= startval && i <= startval + noofelements) {
if(rs.next()) {
// Display Data
%>
<%
}
}
}
} else {
startval = startval * noofelements;
//out.println("start" +startval);
for (int j=1; j<=count; j++) {
if(rs.next()) {
if ( j > startval && j <= startval + noofelements) {
//Display Data
%>
<%
}
}
}
}
//out.println("");
//out.println("| Go To Page: | ");
%>
|
|
| |
| |
| |
<%
if (count!=0)
{
%>
|
navigate
<%
pageend=pageval-1;
startindx = startval1 - 2;
endindx = startval1 + 2;
//out.print(startindx+1);
//out.print(endindx+1);
if(startval1!= 0)
{
%>
« prev
<%
}
else
{
%>
<%
}
for (int j=0; j= startindx && j <= endindx)
{
//out.print(startval1);
if (j==startval1)
{
%>
<%=(j+1)%>
<%
}
else
{
%>
<%=(j+1)%>
<% }
}
}
if(startval1!= pageend)
{
%>
next »
<%
}
else
{
%>
<%
}
%>
|
<%
}
else
{
%>
|
<%
//out.print("No records found");
}
// for paging
%>
<%
// for paging
%>
|
|
|