This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

paging in jsp for multiple queries  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! i would like someone to help me with paging in jsp.my code uses multiple queries and the result is that when i press the next button i get a java null pointer exception.
my code is as follows:Please help,matter pretty urgent
<%@ page language ="java" import=" java.sql.* " %>
<%
String a=request.getParameter("a");
String b=request.getParameter("b");
String c=request.getParameter("c");
String d=request.getParameter("d");
String e=request.getParameter("e");
String f=request.getParameter("f");
String g=request.getParameter("g");
String h=request.getParameter("h");
String i=request.getParameter("i");

String point=request.getParameter("point");
int next,previous;
int pointer=0;
int count=0;
int maxrecords=5;

try
{

Class.forName("gjt.org.mm.mysql.Driver");

Connection myConn=DriverManager.getConnection("jdbc:mysql://servername/password/username");
Statement stmt = myConn.createStatement();
String sql="";
if(point==null)
{
next=0;
previous=0;
//previoos=previous+1;
// change next=next+1;
}
else
{
next=Integer.parseInt(point);
previous=Integer.parseInt(point);
}
sql="select * from tablename where id>="+(next+1);
if(a.length()>0 &&(a!=null))
{
sql= sql + " and a='"+a+"'";
}
if(b.length()>0 &&(b!=null)&& (!b.equals("empty")))
{
sql= sql + " and b='"+b+"'";
}
if(c.length()>0 &&(c!=null))
{
sql= sql + " and c='"+c+"'";
}
if(d.length()>0 &&(d!=null))
{
sql= sql + " and d>='"+d+"'";
}
if(e.length()>0 &&(e!=null))
{
sql= sql + " and e<='"+e+"'";
}
if(f.length()>0 &&(f!=null))
{
sql= sql + " and f>='"+f+"'";
}
if(g.length()>0 &&(g!=null))
{
sql= sql + " and g<='"+g+"'";
}
ResultSet rs=stmt.executeQuery(sql);
ResultSetMetaData rm1 = rs.getMetaData();
//out.println(sql);
%>

<TABLE WIDTH="80%" BORDER="1" ALIGN="center">
<TR>
<Th ALIGN="center" BGCOLOR="#CCFFFF"><B><%=rm1.getColumnLabel(6)%></B></Th>
<Th ALIGN="center" BGCOLOR="#CCFFFF"><B><%=rm1.getColumnLabel(7)%></B></Th>
<Th ALIGN="center" BGCOLOR="#CCFFFF"><B><%=rm1.getColumnLabel(8)%></B></Th>
</TR>
<%
if(rs.next())
{
do
{
out.println("<tr><td>"+ rs.getString(rm1.getColumnLabel(6))+ "</td><td>" + rs.getString(rm1.getColumnLabel(7)) + " </td><td>"
+ rs.getString(rm1.getColumnLabel(8)) + " </td></tr>");

//rs1.getString(rm1.getColumnlabel(1)) + " </tr></tr>");
next++;
//next--;
}while((rs.next())&(next % maxrecords !=0));
//while((rs.previous())&(next % maxrecords !=1));
}

out.println("</table>");
if(previous >1)
{
previous=previous-maxrecords;
//previous=previous+maxrecords;
out.println("<a href='http://localhost:8080/paginginjsp.jsp?point="+previous+"'> previous</a>    ");
}
if(rs.next())
{
out.println("<a href='http://localhost:8080/paginginjsp.jsp?point="+next+"'> next </a>");
}

//pw.println("</body></html>");
myConn.close();
}
catch(SQLException exp)
{
out.println("<H2>Database Error</H2> <B>" + exp.getMessage() + "</B><H4> Please Try Sometime Later</H4>");
}

%>
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi. did you manage to get it? cos currently i need that code too.. pls let me know if you are able to do it.
 
Author and ninkuma
Marshal
Posts: 66801
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch arvindmpai!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
I'd also like to suggest that when posting code to the forums, that you use the UBB code tags. That way, the formatting of your code will be preserved.
Also, this very subject, the paging of large datasets, has been discussed a number of times in these forums. You might find some useful hints by searching this and the Servlets forum for information on paging.
Thanks!
bear
JSP Bartender
[ August 25, 2003: Message edited by: Bear Bibeault ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!