Break up resultset in Java Bean that shows up in JSP

I have a bean that works with a JSP where it shows results from Database. It works great but was wondering if I can split up the results and show 3 parts of my resultset where if I had 30 results I can show 10 records, then show the next 10 records and then show the last 10 records on the same page.
It currently shows like this on the JSP that is using Java Bean to show the results:
1. RecordOne
30. RecordThirty
The bean:
public void setResultData(String resultData)
public getResultData()
   return ResultData;
public void getDB()
//DB connections etc..
while (rs.next())
     String s = rs.getString("eachrecordinfohere");
}JSP with bean where I display database results:
<jsp:getProperty name="dbresult" property="resultData" />
....I want it to show like this where it is split up:
First set of records:
1. RecordOne
10. RecordTen
Second set of records:
11. RecordEleven
20. RecordTwenty
Third set of records:
21. RecordTwentyOne
30. RecordThirty
Here is what I tried but I am getting error messages with my resultset while loop.
StringBuffer bufoutput = new StringBuffer();
public void setResultData(String resultData)
public getResultData()
   return ResultData;
public void getDB()
//DB connections etc..
while (rs.next())
    if (count <= 10)
        bufoutput = ("First set of records:");
        String s = rs.getString("eachrecordinfohere");
    else if((count > 10) && (count < 21))
       bufoutput = ("Second set of records:");
       String s = rs.getString("eachrecordinfohere");
     else if((count > 20) && (count <= 30))
         bufoutput = ("Third set of records:");
         String s = rs.getString("eachrecordinfohere");
int count = 0;
while (rs2.next())
     count++;
}Please advise anyway to get this to work?

Basically it looks like:List<Maintable> results = new ArrayList<Maintable>();
while (resultSet.next()) {
    Maintable maintable = new Maintable();
    maintable.setId(new Long(resultSet.getLong("Id")));
    maintable.setName(resultSet.getString("Name"));
    maintable.setValue(new Integer(resultSet.getInt("Value")));
    results.add(maintable);
}Where Maintable is:public class Maintable {
    private Long id;
    private String name;
    private Integer value;
    // + getters + setters
}Then sublist it and use c:foreach to iterate through it in JSP.

Similar Messages

  • ElGamal - Is there some Java tutorial that shows how this can be done?

    Hello,
    I found this by doing a quick search on Google.com;
    http://www.java2s.com/Tutorial/Java/0490__Security/ElGamalexamplewithrandomkeygeneration.htm
    However I was wondering whether there is Java Tutorial that shows how ElGamal can be implemented in a Java program. I am looking to develop a client / server application that share files between them and I would like to encrypt every file being transmitted.
    Regards,
    Sim085

    Either use linked content or use InCopy Text stories.

  • How to call the method from the java bean and pass it to JSP textbox

    i'm quite new to java thats why i'm asking how to call a method in the java bean file and pass it to the JSP textbox. My projects are communicating JSP with C#. i had successfully created a C# client bean file for JSP. The whole process is to type something on the server(C# programming) and it would appear in the textbox.

    your question doesn't provide much informartion. provide some other information and coding so that we could tell exactly what you are looking for?

  • Where does java beans be to locate in jsp?

    I've problem to understand where Tomcat looks for Java Beans
    - testbean.jsp:
    <html>
    <title>Prova beans</title>
    <body>
    <jsp:useBean id="test" class="lta.FirstBean" />
    </html>- i've put FirstBean.class in:
    MyDomain->MyFolder->WEB-INF->classes->lta->FirstBean.class
    When i launch testbean.jsp, it returns the error below:
    org.apache.jasper.JasperException: /provabean.jsp(5,0) The value for the useBean class attribute lta.FirstBean is invalid.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
    ......I have also try to put file class in:
    MyDomain->WEB-INF->classes->lta->FirstBean.class
    but i got the same error.
    Can someone helps me?
    Thks in advance

    I don't like it. I think you should deploy Web apps
    under Tomcat the way Tomcat expects to see them:
    http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/
    ndex.htmlI follow your suggest but i get another problem.
    I created an application in $CATALINA_HOME/webapps/myapps and i put all *.jsp files in it, then i configured workers2.properties to send only *.jsp and servlet request to Tomcat with:[uri:<mydomain>/*.jsp]
    info=My application folder for Host <mydomain>
    worker=ajp13:localhost:8009
    [uri:<mydomain>/servlet/*]
    info=Prefix mapping
    worker=ajp13:localhost:8009Everything works fine with *.jsp but not for servlets.
    In server.xml:
    <Host name="<mydomain>" appBase="jakarta-tomcat-5.0.27/webapps/<mydomain> " debug="0">
    <Context path="" docBase="">
    <Logger ....>
    </Host>Perhaps i must configure the Context parameters ...

  • Java Beans and Tag Libraries and JSP

    Is it ok to write all the Javacode into a JSP page?
    If not,
    is plain JavaBeans okay or is Tag libraries better.
    Basically I am creating a simple webpage for users to enter info into a database and retrieve information as well.

    Is it ok to write all the Javacode into a JSP page?That's generally considered bad design. It's a good idea to separate the display (JSP) from the rest of the business logic.
    If not, is plain JavaBeans okay or is Tag libraries better.Tag libraries are often used as a good way to separate display and logic.
    Basically I am creating a simple webpage for users to
    enter info into a database and retrieve information as
    well. I'd recommend using JSP for simply displaying the HTML forms or the results of the information retrieval, servlets to receive and handle the HTTP requests, and plain old Java objects (POJOS) as helper classes to do all the data transfer. There are several web frameworks available that can help you out in this regard (Struts, etc.), but there is a learning curve involved and they may be overkill for a (very) small website.
    Hope this helps... :o)

  • Where does WL keep my Java files that it creates from JSPs?

    Hi,
    I'm using WL 9.2.2 on Solaris 9 (JDK 1.5). When WL builds a JSP page, it presumably converts those JSP pages to Java files before compiling them. Where does it keep those Java files? I'm having a hard time figuring out where my NullPointerException is occurring ...
    java.lang.NullPointerException
    at jsp_servlet._jsp._groups.__addgroup._jspService(__addgroup.java:810)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:394)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:309)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
    at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:525)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:261)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at com.myco.nps.im.plugin.NPSIMIntercepter.forwardRequestDirect(NPSIMIntercepter.java:852)
    at com.myco.nps.im.plugin.NPSIMIntercepter.doFilter(NPSIMIntercepter.java:193)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3229)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2002)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1908)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1362)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
    Thanks, - Dave

    It deletes them by default. If you want to preserve them, set the "keepgenerated" and "working-dir" (this one so you don't have to hunt for them) elements in the "jsp-descriptor" element in the weblogic.xml file.
    [http://e-docs.bea.com/wls/docs103/webapp/weblogic_xml.html#wp1038491]

  • Using Java Bean in JSP to show database record

    I have links in my Tomcat container that if someone clicks on a specific link it should go to a Record page (Show.jsp) with all the values associated with a record from a database.
    For example if someone clicks on a specific link like this:
    LinkExample
    it would take you to a jsp with database info for someone named Jones and show you his info:
    Lastname = Jones
    Firstname = Mike
    City = San Diego
    I would like to do this using a Java helper class and bean so I dont have any database connection or Java code in my JSP.
    I created Java class file that has Database connection that works with a Java bean. I just dont know how to get the Show.jsp to work with the Java Bean and Java helper class file.
    Here is what I have for Show.jsp and this is the part I have been working on the longest but cant get it to work because it doesnt seem to work with the database:<jsp:useBean id="user" class="num.UserDB"/>
    //do I call getUser(lastname) here and if so how?
    <jsp:setProperty name="user" property="*"/>
    Last Name: <jsp:getProperty name="user" property="lastname"/><BR>
    First Name: <jsp:getProperty name="user" property="firstname"/><BR>
    City: <jsp:getProperty name="user" property="city"/><BR>My Java Helper class that compiles and connects to database:
    package num;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import num.User;
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName...//database connection stuff here
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
            user.setFirstname(results.getString("city"));
         catch(Exception e)          
                   System.out.println("Exception...");               
       return user;
    }My Java Bean that compiles here:
    package num;
    public class User
      private String firstname;
      private String lastname;
    private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, String city)
           this.lastname = lastname;
              this.firstname = firstname;
              this.city = city;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      //more bean methods for all fields here
     

    Sorry if I wasnt specific enough. I have a link that passes a value (field that is passed is called lastname) to a JSP where I want to show record info for that value that is passed.
    My question is how do I show the database record info on Show.jsp for the lastname field value of Jones where I want to use a Java Bean and Database helper class in Show.jsp
    Here is the message I get when I hit the link (LinkExample) and it goes to Show.jsp:
    org.apache.jasper.JasperException: Cannot find any information on property 'lastname' in a bean of type 'num.UserDB'
    .....My UserDB class:
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName("org.gjt.mm.mysql.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dbconnone?user=smitherson&password=abcdefg");
        Statement stmt = conn.createStatement();
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
                         user.city(results.getString("city"));
         catch(Exception e)          
             System.out.println("Exception..." + e);          
       return user;
    }Bean class:
    package num;
    public class User
      private String firstname;
      private String lastname;
      private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, Sting city)
          this.firstname = firstname;
           this.lastname = lastname;
    this.city = city;
      public String getFirstname()
              return firstname;
      public void setFirstname(String firstname)
         this.firstname = firstname;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      public String getCity()
              return city;
      public void setCity(String city)
         this.city = city;
      

  • Storing Result in Java Bean

    Hi All.
    I m a new member on this forum.Posting my first question here.Hope some one will reply me. I got a assignment in which I have to store Result Set in java bean. I am using JSP. I dont know what java bean is and how we store data in Java bean.And then Java bean should provide a method to show the result in tabular format. Thanks in advance.

    A java bean is nothing more than a class that holds information. Here is one:
    public class Person
         private String name;
         private String zipcode;
         public void setName(String theName)
              name = theName;
         public String getName()
              return name;
         public void setZipcode(String theZipcode)
              zipcode = theZipcode;
         public String getZipcode()
              return zipcode;
    }Now if you have a resultset containing a name and a zipcode, you can store each record in an object of the above type.
    I don't understand what you mean by "tabular format". Could you explain that further?

  • Java Bean Connectivity and Closing Connections (XI 3.0)

    Hi guys,
    We have existing Java Beans that we would like to use with Crystal Reports. Our current Java beans return a disconnected GridModel and explicitly close the connection immediately after so that they can be returned to the connection pool (Oracle).
    Once we modified these beans to return ResultSets we found that closing the connection also closes all the associated ResultSets and Statements.
    What is the best practice here?
    Modify the Java bean to close the connection in the finally block?
    Will Crystal clean up after itself?
    I also see there is something called a CachedRowSet which is disconnected:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html
    Is this supported by Crystal?
    Thanks,
    Kevin D Lee =)

    Hello Kevin,
    Enterprise XI 3.0 CRConfig.xml points to Java JRE 1.5 provided with the install, so you should be ok with the CachedRowSet. 
    It's used by other customers for disconnected operation.
    Since you're going to Oracle, you'd likely encounter issues mapping Oracle fields to POJO property types.
    Furthermore, POJO Factory libraries that were shipped with Crystal Reports XI Release 2 aren't shipped with Enterprise XI 3.0, so you'd not find that an out-of-the-box option. 
    Another alternative to CachedRowSet is to define callback method in your JavaBeans class that Crystal will call when it's done with the data source. 
    This has been implemented in XI 3.0 (track ADAPT00877915) - excerpt from the track note:
    <JavaBeans>
        <CacheRowSetSize>100</CacheRowSetSize>
         <JavaBeansClassPath>c:\javabeans\</JavaBeansClassPath>
         <CallBackFunction>CrystalReportsLogoff</CallBackFunction>
    </JavaBeans>
          Customer can configuration the <CallBackFunction/> to let CR know
          which function should be invoked when loging off.
    Advantage of CachedRowSet is that you can immediately close it after you've read all the data, disadvantage would be the default implementation stores all data in memory.
    Advantage of the callback method is that it would use the JavaBean you've supplied (and not load all data immediately in memory), but callback won't be called immediately, but only after the report is done with.
    Sincerely,
    Ted Ueda

  • How to deploy java bean in Oracle Applications?

    There is a Oracle Applications Forms FNDMNMNU.fmb which calls a Java Bean to show TreeView.
    The Bean Area uses the implementation class of AppletAdapter.class. Do you know that we have to use the same AppletAdapter class so that we can connect to Oracle database?
    In the form of FNDMNMNU.fmb, the java bean is called like this.
    fndaplt.applet_init('FND_MENUS.TREE_VIEWER',
    'FS',
    'oracle.apps.fnd.functionSecurity.client.FunctionTreeViewer',
    l_list_id);
    Do you know what 'FS' means ?
    Thank you very much in advance!
    It is my first time to use Java Bean in Oracle Applications!

    HI srini ,
    my application version 12.0.4 and database is 10.2.0.4
    and i want to restrict the No of users
    exp i have have 500 users and i want restrict to 100 only
    how can i do that please explain
    Thanks,
    Sudheer

  • URGENT! Java Bean Query

    I am using Tomcat 3.1 and MySQL database for an application I am designing. Below is the code for a java bean that registers users details. The code compiles correctly, but I would like to know if there is any code that I might have left out? What changes should I make to make it more user friendly?
    I do not want to use servlets, as they are very difficult to setup.
    REGISTRATION.JAVA
    package gcd;
    import java.sql.*;
    import java.util.*;
    import java.lang.*;
    import java.awt.*;
    import java.text.*;
    import java.io.*;
    import com.mysql.jdbc.*;
    public class Registration
         public Registration(){}
    String first_name;
    String last_name;
    String role;
    String email;
    String error;
    java.sql.Connection con;
    public void setFirstName( String value )
    first_name = value;
    public void setLastName( String value )
    last_name = value;
    public void setRole( String value )
    role = value;
    public void setEmail( String value )
    email = value;
    public String getFirstName()
    return first_name;
    public String getLastName()
         return last_name;
    public String getRole()
         return role;
    public String getEmail()
         return email;
         public void connect() throws ClassNotFoundException, SQLException, Exception
    try
    System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://localhost/gcdBB_db","","");
    catch (ClassNotFoundException e)
    error = "ClassNotFoundException: Could not locate DB driver.";
    throw new ClassNotFoundException(error);
    catch (SQLException e)
    error = "SQLException: Could not connect to database.";
    throw new SQLException(error);
    catch (Exception e)
    error = "Exception: An unknown error occured while connecting to database.";
    throw new Exception (error);
         public void disconnect() throws SQLException
    try
    if(con != null)
    con.close();
    catch (SQLException e)
    error = ("SQLException: Unable to close the database connection.");
    throw new SQLException(error);
    public java.sql.ResultSet validateRegistration(String firstname, String lastname, String role, String email) throws SQLException, Exception
    java.sql.ResultSet rs = null;
    try
    String queryString = ("INSERT INTO registration (firstname,lastname,role,email) VALUES ('" + firstname + "','" + lastname + "','" + role + "','" + email + "';");
    java.sql.Statement stmt = con.createStatement();
    rs = stmt.executeQuery(queryString);
    catch (SQLException e)
    error = "SQLException: Could not execute the query.";
    throw new SQLException(error);
    catch (Exception e)
    error = "An exception occured while retrieving users.";
    throw new Exception(error);
    return rs;
    Thanks,
    Niall

    in JavaBean class:
    The setting/getting method should be matched with the first letter capitalized. ie.
    String firstName;
    String lastName;
    public void setFirstName(String value) { firstName = value ; }
    public String getFirstName() { return firstName; }
    public void setLastName(String value) { lastName = value ; }
    public String getLastName() { return lastName; }
    String role and email coded correctly.
    remember: put your bean in package and call from package.

  • How to pass a populated Java bean to a jsp

    Hi,
    I'm new to J2EE world. I want to know how should I pass a populated Java Bean (not EJB) to a JSP without displaying that JSP in the next step. I would be much grateful to anyone who gives a solution to my problem.
    Thanks in advance
    With best regards
    Sampath

    > I'm new to J2EE world. I want to know how should I
    pass a populated Java Bean (not EJB) to a JSP without
    displaying that JSP in the next step.
    Urk?
    A JSP is meant to be displayed. If there's business logic in that JSP, get it out of there. Process the bean as needed on the server side and send the flow on to some view that actually should be displayed.
    ~

  • How to access java bean in a script

    I have a java bean that has session scope . I would like to change attribute of this bean. When a user click�s a link I have to change attribute of this bean. I would like to implement using html:link like this .
    <html:link action="viewresults.do" onclick='javascript:increment()' >Results</html:link>
    How can I do that in a java script.
    Thank you in advance

    You cannot do it in the javascript. your javabean is in server memory and can be accessed on server side. Can't you do it in the action that handles viewresults.do request?

  • Java Bean to check for Well-formed  XML DOC?

    Hi All,
    I am new to the Java XML API's. Does anyone have an example of
    a Java Bean that i can pass an XML String and check if the
    XML document is well formed?
    Thanks
    Joe

    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xmlString)));try/catch this ugly line, if no parse exception and a non -null doc exists then your XML is well-formed.
    of course if your XML contains namespaces, you would have to setup correctly the document builder.

  • What makes a Java Bean invaild for a model import?

    I'm busy prototyping some functionality that will expose some MDM 5.5 data through a WebDynpro application.  I'm having a problem creating a java bean that will sit in front of an EJB, in that the Bean importer will refuse to import a bean if a certain line of code in a method is visible.  Here's the offending code from the method:
    try {
         A2iResultSet rs = cat.GetRecordsByValue(ary, rsd, Schema.MyTable.NAME);
         setEventLocation(rs.GetValueAt(0, Schema.MyTable.EVENT_LOCATION).GetStringValue());
    } catch (StringException e) {
         setEventLocation("failed to find record");
    Note that I have a class instance variable called 'eventLocation', which has get/set methods defined for it, thereby satisfying the Javabean requirement.
    The first two lines of the 'try' block are the problem.  If I comment them out and assemble the DC, I can import the Bean into a model with no issues.  If I uncomment them, I cannot import the bean - I get a message that says 'Invalid Jar - no beans to import'.
    Can someone explain why this is happening?  Does it have something to do with the StringException?  As far as I can tell from the Java bean model import documentation, I think I'm doing everything correctly, but something must be amiss.
    Suggestions?

    Pablo,
    Now I understand your question in comments to my blog better
    You have to add "ejb20" classes to your WebDynpro project as well, and import model afterwards.
    In WebDynpro DC expand path (<project> -> DC MetData -> DC Definition -> Used DC) and invoke "Add Used DC..." in contextual menu. In dialog select "<dev. config> -> SAP-J2EE -> ejb20 -> DC MetaData -> Public Parts -> default". Set dependencies Built-time (probably Design-time as well). Click OK. Try to import model. If fails, restart IDE and try to import again.
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com/

Maybe you are looking for

  • Can not find product , sku attributes data in database table

    Hi there, I find it really strange to find data in database related to product and sku. I set up the commerce reference store and store is up and running fine. Catalog is fine too. I am not able to find data related to sku attributes in database. I h

  • Why is it so hard to copy pictures from my iPhone to my iPad?

    I want to use iCloud to backup both my iPhone and iPad, but not any of the pictures on these devices.  I want to backup the pictures to my iMac, since they take up so much space.  What is the best way to do this?  What is the correct way to copy pict

  • Why are the system preferences set to disallow downloading Internet content/applications?

    I just purchased a refurbished iMac from the Apple Store.  I am attempting to install Apache OpenOffice for Mac, but a message appears that says, "open office cannot be opened because it is from an undentified developer.   Your security preferences a

  • Help with DiskWarrior error message

    File "com.apple.scheduler7098.plist" Detected that property list data is damaged and cannot be repaired. Conversion of data failed. The file is not utf-8, or in the encoding specified in the xml header if xml. Locations: "Macintosh/Users/Name/Libary/

  • Reg sap hr

    Hi gurus.... what is BPML...Business process master list..?In detail regards krishna