How do I break up a result set over various pages?

I would like some example code of how to breakup a result set that I am using in a form.
There are too many results for the form to currently work properly on one page so I have to do it over several web pages, using a next page link etc...
I am currently using servlets.
If anyone has an idea of how to do this differently have at it and let me know what to do. I prefer code examples.

I would change the select query so that it doesn't return the whole resultset. Check your database manual to see if your database supports something like limit. E.g. this query will only return the 20 first records if you are using mysql.
select *
from tablename
limit 0,20
Kaj

Similar Messages

  • Does break work for result set ?

    while(rs.next())
    if(true)
    break; // does break work for result set ?
    break is not working when i wanted to go out of while loop like above. how can i go out when condition matches ?

    Well this is what i learned and i'm learning in
    school.So what does your school tell you is the only correct indenting style?
    The "break or not" discussion has been around ever since, and there is no agreed-upon solution that says "always do it" or "never do it".
    You don't have to write nice code. The important
    thing is that you code's performance! This is complete bullshit.
    You client will never read your code, (only if it is
    open source or a script).But the guy who maintains it. Sorry, but this is really ignorant. Unclear code will lead to bugs that are difficult to find and resolve. "Optimizations" will lead to more bugs.
    This all leads to longer development time, late project and increased project and maintenance costs. Ask your customer if he really wants that.

  • How should i use the two results sets in one single report data region?

    Hi frnz,
     I have to create a report using the below condition...
    Here my given data  set query gives you the two result sets ,so how should i use that two result sets information in single report....when i accessing that data set query it will take the values off the first result set not for the second result set.
    without using sub report and look up functionality..... if possible
    is there any way to achieve this.....Please let me know..
    Thanks!

    You cant get both resultsets in SSRS. SSRS dataset will only take the first resultset
    you need to either create them as separate queries or merge them into a single resultset and return with ad additional hardcoded field which indicates resultset (ie resultset1,resultset2 etc)
    Then inside SSRS report you can filter on the field to fetch individual resultsets at required places. While merging you need to make sure metadata of two resultsets are made consistent ie number of columns and correcponding column data types should be same.
    In absence of required number of columns just put some placeholders using NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to get previous row of result set in select query?

    I want to access the previous row of an result set obtained yet, in the same selectquery .
    How can I do that?

    Use analytical functions.
    For example:
    create table top_n_test (
       a number,
       b varchar2(10)
    insert into top_n_test values (1,   'one');
    insert into top_n_test values (2,   'two');
    insert into top_n_test values (3, 'three');
    insert into top_n_test values (4,  'four');
    insert into top_n_test values (5,  'five');
    insert into top_n_test values (6,   'six');
    insert into top_n_test values (7, 'seven');
    insert into top_n_test values (8, 'eight');
    insert into top_n_test values (9,  'nine');
    commit;
    select a, b from (
      select
        a,b,
        rank() over (order by b) r
      from
        top_n_test
    where
      r<4;
             A B
             8 eight
             5 five
             4 fourHTH
    Ghulam

  • How to Add extra data in result set of cfquerry?

    hi all,
    I am new to cold fusion please help me
    i am using the cfquery tag for executing a select query and getting the system name and system is from that........
    But i want an extra system name and system id to add to the result of that query with out changing the data base ..............
    please any one suggest me ...........IT's URGENT
    Thanks in advance
    Sudheer

    You'll have to use an array and the function queryAddColumn. An example follows.
    Suppose I have a result set called myQuery. There are 5 rows in it. I wish to add 2 new columns to the query, on the fly. The column names are username(type varchar) and userID(type integer)
    <!--- Create array corresponding to column username--->
    <cfset usernameArray = ArrayNew(1)>
    <cfset usernameArray[1] = "[email protected]">
    <cfset usernameArray[2] = "[email protected]">
    <cfset usernameArray[3] = "[email protected]">
    <cfset usernameArray[4] = "[email protected]">
    <cfset usernameArray[5] = "[email protected]">
    <!---
    The next line adds the new column, username, to the query. That's it. Done.
    The array indices correspond to the row numbers in the query.
    The function queryAddColumn returns the column number for the newly added column
    (in case you'll need it, which you usually wont ).
    --->
    <cfset columnNumber = queryAddColumn(myQuery, "username", "VarChar", usernameArray)>
    <!--- Now, do the same for the next new column, userID  --->
    <cfset userIDArray = ArrayNew(1)>
    <cfset userIDArray[1] = "23">
    <cfset userIDArray[2] = "121">
    <cfset userIDArray[3] = "9">
    <cfset userIDArray[4] = "76">
    <cfset userIDArray[5] = "44">
    <cfset columnNumber = queryAddColumn(myQuery, "userID", "integer", userIDArray)>

  • How to create a browsable, distributable result set?

    I want do develop a web application, which must be able to browse (previous page, next page) in large result sets. The web application is distributed on several servers (persistent session). What is the way to handle this?

    The web application is distributed on
    several servers (persistent session). What is the way
    to handle this?Can you explain what a persistent session distributed on serveral servers means?

  • How can I create 2 columns that go over several pages? f.e. Contract with 2 languages.

    I need to create 2 columns over several pages.
    Target is a bilingual german/english contract.
    All paragraphs side by side. Left side german right side english.
    My problem is that if I use standard columns the text flows on the next column of the same page instead of same clumn on next page.
    Example:
    I do not like
    EN     EN
    EN     EN
    EN     EN
    EN     EN
    I need.
    EN     GER
    EN     GER
    EN
    EN
    EN
    EN
    EN
    EN
    Can anyone help. Do I have to back to MicrosoftWord.
    Please not. Thank you.

    HI,
    You could use two sets of linked text boxes, as I've done here.
    The text layer of this document contains only a series of Page Breaks, necessary to create the pages on which the Text boxes are placed. The illustration shows parts of pages 1 and 2.
    Create the series of text boxes that make up the left column, then Select All and Duplicate to create the second set.
    I found alignment a bit of a hassle, and that alone might be enough to convince you to use MS Word (or the word processing module of one of the free Office applications) for this task.
    You might also use the Provide Pages Feedback menu item in the Pages menu* to make a feature request to Apple.
    Regards,
    Barry
    * Got it right this time, fruhulda!

  • How to avoid duplicates for an result set

    how to avoid the duplicate rows for the below query
    SELECT  to_char(grecode (titleid)) gre_code, to_char(toeflcode (titleid)) toefl_code,titleid
              FROM (SELECT DISTINCT TO_CHAR
                                       (UPPER (TRIM (get_clob_value (table_name,
                                                                     KEY
                                       ) RESULT,
                                    titleid
                               FROM mcp_specifications a JOIN mcp_title_specifications b
                                    ON a.specificationid = b.specificationid
                                    JOIN mcp_titles c ON b.titleid = c.titleid
                              WHERE b.is_parent = 'F'
                                AND UPPER (TRIM (c.university_state)) =
                                                              UPPER (TRIM ('USA'))
                                AND TO_CHAR (get_clob_value (table_name, KEY)) IS NOT NULL
                                AND UPPER (TRIM (SPECIFICATION)) IN
                                                       (UPPER (TRIM ('program'))))
             WHERE UPPER (TRIM (RESULT)) = UPPER (TRIM ('COMPUTER SCIENCE'))
          ORDER BY RESULT ASC;the output of the query would be
    gre_code    toefl_code   titleid
    402             78             5518
    402             78             5519
    402             78             5520
    402             78             5521the output should be
    402 78 any titleid

    Some simplified code:
    SELECT grecode(titleid) gre_code,
           toeflcode(titleid) toefl_code,
           min(titleid) titleid
    FROM   (SELECT DISTINCT TO_CHAR(UPPER(TRIM(get_clob_value(table_name,KEY)))) RESULT,
                   titleid
            FROM   mcp_specifications a
                   JOIN mcp_title_specifications b
                        ON a.specificationid = b.specificationid
                   JOIN mcp_titles c
                        ON b.titleid = c.titleid
            WHERE  b.is_parent = 'F'
            AND    UPPER(TRIM(c.university_state)) = 'USA'
            AND    TO_CHAR (get_clob_value (table_name, KEY)) IS NOT NULL
            AND    UPPER(TRIM(SPECIFICATION)) = 'PROGRAM')
    WHERE  UPPER(TRIM(RESULT)) = 'COMPUTER SCIENCE'
    GROUP BY grecode(titleid),
             toeflcode(titleid)Please note that applying functions like UPPER and TRIM on a string literal can and should be avoided.
    For example:
    UPPER(TRIM('USA')) = 'USA'Why force the database to do both an UPPER and a TRIM on something that can just be represented in uppercase with no surrounding spaces? It's a waste of time.

  • How to get Difference of a Result set in reports

    Hello,
    I am trying to get difference (variance) of sales in past year and current year. Below is the report which accumulates the sales for 2013 and 2014 and also accumulates the Sales for both year , but how can we get the difference of sales in Years. Any ideas really appreciated.
    Thank you,
    Pavan

    Harish,
    I tried creating Some restriction Key figures and calculated key figures as I want this by every month as well. Not a straight forward (easy)way. I had to create many Key figures.
    I really appreciate your response.
    Thank you,
    Pavan.

  • How to show all the search result in a report page

    I have a report page which the user can enter first or last name to find the matched employees. The current report only show maximum of 15 matched results. How to show all of them in one page if more than 15.
    Also, the employee name on the report is a link, how to make the link to be conditional. ( I mean it can be a link or not based on another column)
    Thanks.
    Jen

    Hi, you can change the number of rows on the report definition page (15 is the default value)- that's also where you can change pagination and max. number of rows etc.
    About the second question - you will have to use Case or Decode in your report query and have the value as link or not based on the condition column, something like:
    Select Decode(condition_column, 'link_value', '<a href="f?p=YOUR_APP:PAGE_TO_LINK_TO:'  || :SESSION || ':::::">display_column</a>' , display_column) From .....
    Hope this helps.

  • Passing array result set between Viewstack pages

    Hi, all.
    I want to use an array result in various Viewstack pages. So
    the main application run a RemoteObject call, gives the result to a
    function that makes the area. I then want to call the array result
    from other pages in the Viewstack. Is there a way to reference from
    the other pages? I cannot seem to do it. Thanks.
    I would add my code, but I cannot find the Attach Code thing
    they are talking about.

    Eric and Tracy,
    Thanks for these suggestions. I will try them. I think the
    real issue is knowing HOW to call back to the "parentApplication"
    (whatever that is. ;) I just learned something new, thanks).
    I do appreciate the more in-depth how-to's, having come from
    the procedural world of CF. Like many starting to use Flex, I sort
    of fell into this field, having no real background or formal
    programming experience and learning by example is really useful. I
    mainly did business development before getting into Flex
    programming.
    Like learning to talk in another country that also uses sign
    language and clicks in the vocabrulary, we have to learn a whole
    new vocabulary and even way of thinking about what and how we say
    things. Again, thanks for the patience and time.
    Gary McNeel
    Struggling Flex Coders Anonymous Member Since 2007

  • How Can I speed  up the results on my JSP page with the help of Caching.

    I am generating a dropdown listbox by merging an xml file with a style sheet(xsl).
    This list box comes up fine without any problems. Now, I am adding some advanced
    logic to the
    style sheet (xsl) to use the same xml file in a more efficient way. This time
    the generation
    of the list box is taking much longer (upto 25 seconds) although I get the results
    I want.
    Is there any way I could speedup this process by using weblogics caching. I know
    the process is slowing down
    due to the code in the stylesheet. Will caching resolve this issue?. I tried
    using
    <wl:cache> </wl:cache> on the jsp page generating this listbox but found no improvement.
    Any help will be very much appreciated.

    turn off your phone, unplug your router, leace it off for 30 seconds, and then power it back on and turn the iphone back on

  • How to display result set boolean value as a check box

    Hi guys,
    I am getting the data which include boolean from the database, i need to display the boolean values as check box, see my code, its displaying the data into the table with the boolean values as true and false, how to make it in check boxes
    package swing2.org;
    import java.awt.GridBagLayout;
    import javax.swing.JPanel;
    import java.awt.Color;
    import javax.swing.BorderFactory;
    import javax.swing.border.BevelBorder;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.ComponentOrientation;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    public class Panel2 extends JPanel {
         private static final long serialVersionUID = 1L;
         private JScrollPane jScrollPane = null;
         private JTable jTable = null;
          * This is the default constructor
         public Panel2() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
         //     Panel2.ResultSetFrame();
              GridBagConstraints gridBagConstraints = new GridBagConstraints();
              gridBagConstraints.fill = GridBagConstraints.BOTH;
              gridBagConstraints.gridy = 0;
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              gridBagConstraints.gridx = 0;
              this.setSize(340, 200);
              this.setLayout(new GridBagLayout());
              this.setBackground(new Color(171, 211, 224));
              this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), null));
              this.add(getJScrollPane(), gridBagConstraints);
          * This method initializes jScrollPane     
          * @return javax.swing.JScrollPane     
         private JScrollPane getJScrollPane() {
              if (jScrollPane == null) {
                   jScrollPane = new JScrollPane();
                   jScrollPane.setViewportView(getJTable());
              return jScrollPane;
          String[] columnNames = {"Task Description",
                 "Time ",
                 "Pop-up",
                 "Sound",
                 "Delete"};
          * This method initializes jTable     
          * @return javax.swing.JTable     
         private JTable getJTable() {
                      ResultSetFrame oo = new ResultSetFrame();
                      JTable table = new JTable(oo.model);
                      table.setBackground(new Color(195, 217, 230));
                      table.setComponentOrientation(ComponentOrientation.UNKNOWN);
                      table.setShowGrid(true);
                      table.setShowVerticalLines(true);
                      table.setRowHeight(17);
                      table.setShowHorizontalLines(true);
                      return table;
    abstract class ResultSetTableModel extends AbstractTableModel
         public ResultSetTableModel(ResultSet aResultSet)
              rs = aResultSet;
          try
               rsmd = rs.getMetaData();     
          catch(SQLException e)
               System.out.println("Error " + e);
       public String getColumnName(int c)
       {  try
          {  return rsmd.getColumnName(c + 1);
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return "";
       public int getColumnCount()
       {  try
          {  return rsmd.getColumnCount();
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return 0;
       protected ResultSet getResultSet()
       {  return rs;
       private ResultSet rs;
       private ResultSetMetaData rsmd;
    class CachingResultSetTableModel extends ResultSetTableModel
    {  public CachingResultSetTableModel(ResultSet aResultSet)
       {  super(aResultSet);
          try
          {  cache = new ArrayList();
             int cols = getColumnCount();
             ResultSet rs = getResultSet();
             /* place all data in an array list of Object[] arrays
                We don't use an Object[][] because we don't know
                how many rows are in the result set
             while (rs.next())
             {  Object[] row = new Object[cols];
                for (int j = 0; j < row.length; j++)
                   row[j] = rs.getObject(j + 1);
                cache.add(row);
          catch(SQLException e)
          {  System.out.println("Error " + e);
       public Object getValueAt(int r, int c)
       {  if (r < cache.size())
             return ((Object[])cache.get(r))[c];
          else
             return null;
       public int getRowCount()
       {  return cache.size();
       private ArrayList cache;
    class ResultSetFrame 
    {  public ResultSetFrame()
          /* find all tables in the database and add them to
             a combo box
          try
          {  Class.forName("com.mysql.jdbc.Driver");
             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/task","root","nbuser");
                stmt = con.prepareStatement("SELECT * FROM tasky");
                   try
                    String query = "SELECT * FROM tasky";
                    rs = stmt.executeQuery(query);
                    model = new CachingResultSetTableModel(rs);
                    JTable table = new JTable(model);
                    scrollPane = new JScrollPane(table);
                catch(SQLException e)
                     System.out.println("Error " + e);
          catch(ClassNotFoundException e)
          {  System.out.println("Error " + e);
          catch(SQLException e)
          {  System.out.println("Error " + e);
       private JScrollPane scrollPane;
       public ResultSetTableModel model;
       private ResultSet rs;
       private Connection con;
       private Statement stmt;
    }

    add a
    public Class getColumnClass(int col) {
         return getValueAt(0, col).getClass();
    }in your ResultSetTableModel which extends AbstractTableModel.
    A simple example
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.SwingUtilities;
    import javax.swing.table.AbstractTableModel;
    public class SimpleDemo extends JFrame {
        public SimpleDemo() {
            createAndShowUI();
        private void createAndShowUI(){
            String[] columnName = {"CheckBox Column", "Data Column"};
            Object[][] data = {{new Boolean(true), "Data 1"},
            {new Boolean(false), "Data 2"}, {new Boolean(true), "Data 3"}};
            MyModel model = new MyModel();
            model.setData(columnName, data);
            JTable myTable = new JTable(model);
            JScrollPane scrollPane = new JScrollPane(myTable);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            getContentPane().add(scrollPane);
            pack();
            setLocationRelativeTo(null);
        class MyModel extends AbstractTableModel {
            String[] columnName;
            Object[][] data;
            public void setData(String[] colName, Object[][] theData) {
                this.columnName = colName;
                this.data = theData;
                fireTableStructureChanged();
            public String getColumnName(int column) {
                return columnName[column];
            public Object getValueAt(int rowIndex, int columnIndex) {
                return data[rowIndex][columnIndex];
            public int getRowCount() {
                return data.length;
            public int getColumnCount() {
                return columnName.length;
            public Class getColumnClass(int c) {
                return getValueAt(0, c).getClass();
        public static void main(String[] args){
            Runnable run = new Runnable(){
                public void run(){
                    new SimpleDemo().setVisible(true);
            SwingUtilities.invokeLater(run);
    }

  • Jdbc Result Set

    I would like to find out how to break a large result set (say 1000 records) into smaller blocks (say 50)!! Just like some of the web sites where you can view the first 50 results, then press a button to see the next 50...
    Any input will be appreciated!!
    Thanks.

    There are many ways to do this. You could write your query to return a subset of the results, say 25-50, 75-100, etc. You could write a SQL procedure that does this for you. You could get all the rows of the result set and store them in the session, or memory, as a Vector and only display the ones you're interested in.

  • Put database result set into a vector?

    I have a resultset rs I would like to put into a vector but I don't seem to get something fundamental. I can put individual items in with add() for instance but how do I dump a whole result set in there...
    and if I do so should I turn them all to strings before putting them into the vector?
    Any general advice would be appreciated, I've read a lot about Vectors today and have ended up more confused than I'd have expected. So I have come to seek some basic advice.
    private static void showResult (ResultSet rs) throws SQLException {
                            Vector vector = new Vector();
             try
                     // rs is the resultset output from a database
                                      vector.addAll(rs);
             catch(NullPointerException ex)
                    System.out.println("bugger - null pointer exception");
                    System.out.println();
                    ex.printStackTrace();
    }

    Iterate over the resultset, create your own object to store data for each row and add that object to the vector. There is no escape from this.
    catch(NullPointerException ex)You should not be handling Runtime exceptions. You need to take care not to let them occur through your coding logic.

Maybe you are looking for