Discussions

Web tier: servlets, JSP, Web frameworks: urgent!!!!!!!help me out

  1. urgent!!!!!!!help me out (9 messages)

    can anybody tell me how to set the property of resulset which will return only specific number of rows and each set of resultset is dispalyed on different page(as it appears in google)

    Threaded Messages (9)

  2. urgent!!!!!!!help me out[ Go to top ]

    Hi,

    You can make use of
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet resultSet=stmt.executeQuery("your query");
     
    Now you can use resultset.absolute(int rowno);

    Example :

    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;


    public class DisplayRecords extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out= res.getWriter();
    ResultSet resultSet;
    try{
    Class.forName("Driver");
    Connection conn=DriverManager.getConnection("jdbc:oracle:" "userName","password");
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet=stmt.executeQuery("ur Query");
    out.println("<center> <b> The Result Are </b> </center>");
    out.println("<table border=1>");
    int j=0;
    int val=10;

    while(resultSet.next()){
    if(j<val){
    out.println("<tr><td>"+j+"</td><td>"+resultSet.getString(2)+"</td></tr>");
    }else {
    val=val+val;
    break;
    }
    j++;
    }
    }catch(ClassNotFoundException cnf){
    System.out.println("Class not found " +cnf);
    }catch(SQLException sqe){
    System.out.println("Sql Exception " +sqe);
    }
    }
    }

    pass resultset and val to ur nextset servlet and
    display it using resultset.absolute(val);


  3. urgent!!!!!!!help me out[ Go to top ]

    Hi, I was looking for this for long time, but when I try your code ( servlet DisplayRecords) it only show me the val records, I think that I still does not understan what did you mean by :
    " pass resultset and val to ur nextset servlet and
    display it using resultset.absolute(val) "

    Please would you like give me an example on how to do it.
    Thanks, your help will be appreciated.
  4. urgent!!!!!!!help me out[ Go to top ]

    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class TempServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out= res.getWriter();
    ResultSet resultSet;
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn=DriverManager.getConnection("jdbc:oracle:oci8:@Name", "UserName","Password");
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet=stmt.executeQuery("select field1, field2, field3 from tableName");
    out.println("<form name=form action=TempServlet>");
    out.println("<center> <b> The Result Are </b> </center>");
    out.println("<table border=1>");
    int j=0;
    int val=0;

    System.out.println(req.getParameter("value"));
    //I am checking for the Value of J
    if(req.getParameter("value")==null){
    j=0;
    val=10;
    }else {
    j=Integer.parseInt(req.getParameter("value"));
    val=Integer.parseInt(req.getParameter("incrementValue"))+10;
    //The absolute method will move the resultset cursor to particular row
    resultSet.absolute(j);
    }

    //The variable val is to display 10 records in a page

    System.out.println("The value of J is : " +j + " the Value is :" +val);

    while(resultSet.next()){
    if(j<val){
    out.println("<tr><td>"+j+"</td><td>"+resultSet.getString(2)+"</td></tr>");
    }else {
    break;
    }
    j++;
    }
    out.println("<input type=hidden name=value value="+j+">");
    out.println("<input type=hidden name=incrementValue value="+val+">");
    }catch(ClassNotFoundException cnf){
    System.out.println("Class not found " +cnf);
    }catch(SQLException sqe){
    System.out.println("Sql Exception " +sqe);
    }
    out.println("<input type=submit value=submit>");
    out.println("</form>");
    }
    }

    Hope this will help you.

    savitha
  5. urgent!!!!!!!help me out[ Go to top ]

    Thanks for replying again, I appreciate your helps,
    But please how can I get the next 10 records, and when I get there how can I go to the previous 10 records.

    Thanks lot
  6. urgent!!!!!!!help me out[ Go to top ]

    Hi,
    Thanks Savitha,
    Your code is working. But API for JDBC 2.0 is not supported by the driver(jdbc:odbc for Sql server).The reason may be diffrent. Please suggest.
    Prashant
  7. urgent!!!!!!!help me out[ Go to top ]

    Hi Prashant
     could you please send me your code, I still does not know how to do it so it looks somthing like google.com site.
    yna54 at onebox dot com
    Thanks, your help will be appreciated.
  8. urgent!!!!!!!help me out[ Go to top ]

    Hi, I am sorry forget my last posting , savitha code is working fine, just I am wandering
    1) how could we add the previous button to the code ?
    2) hot to add the number of the pages links in the bottom like tha one in google.com.

    Thank you very much savitha
  9. urgent!!!!!!!help me out[ Go to top ]

    Hi savitha,
    I am trying to add a previous button to your code, but I get confused, would you like please tell me what's wrong in this implemetation :

    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class TempServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out= res.getWriter();
    ResultSet resultSet;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:data", "","");
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet=stmt.executeQuery("SELECT * FROM employee ");
    out.println("<form name=form action=TempServlet>");
    out.println("<center> <b> The Result Are </b> </center>");
    out.println("<table border=1>");
    int j=0;
    int val=0;

    System.out.println(req.getParameter("value"));
    //I am checking for the Value of J
    if(req.getParameter("value")==null){
    j=0;
    val=3;
    }else {
        // this is when we are using Next button
    if (req.getParameter("bsubmit") == "next")
    {
    out.println(" next was pressed...");
    j=Integer.parseInt(req.getParameter("value"));
    val=Integer.parseInt(req.getParameter("incrementValue"))+ 3;
    }
    if (req.getParameter("bsubmit") == "previous")
    {
    out.println(" previuos was pressed...");
    j=Integer.parseInt(req.getParameter("value")) - 3;
    val=Integer.parseInt(req.getParameter("incrementValue"))+ 3;
    }

    //The absolute method will move the resultset cursor to particular row
    resultSet.absolute(j);
    }

    //The variable val is to display 3 records in a page

    System.out.println("The value of J is : " +j + " the Value is :" +val);

    while(resultSet.next()){
    if(j<val){
    out.println("<tr><td>"+j+"</td><td>"+resultSet.getString(2)+"</td></tr>");
    }else {
    break;
    }
    j++;
    }
    out.println("<input type=hidden name=value value="+j+">");
    out.println("<input type=hidden name=incrementValue value="+val+">");
    }catch(ClassNotFoundException cnf){
    System.out.println("Class not found " +cnf);
    }catch(SQLException sqe){
    System.out.println("Sql Exception " +sqe);
    }
    out.println("<INPUT type=submit name=\"bsubmit\" value=\"next\">");
    out.println("<INPUT type=submit name=\"bsubmit\" value=\"previous\">");

    // out.println("<input type=submit value=Next>");
    out.println("</form>");
    }
    }
     
  10. urgent!!!!!!!help me out[ Go to top ]

    In my previous adding of a previous button :
    instead of
    if (req.getParameter("bsubmit") == "previous") put
    if (req.getParameter("bsubmit").equals("previous"))

    the same for next button.
    But it still little bit not working, please try it and correct me, I think I did a mistake that I can not see.
    Thanks