how to show only 11 to 20 records out of 1000 records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dcbtux
    New Member
    • Feb 2010
    • 3

    #1

    how to show only 11 to 20 records out of 1000 records

    how to show only 11 to 20 records out of 1000 records through jdbc
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Could you show the code to display records 1 - 10? Then we can customize your code a lot easier.

    Comment

    • dcbtux
      New Member
      • Feb 2010
      • 3

      #3
      Showing 1-10 records is done by a method of Statement Class named setMaxRows(int) . Code is as follows......
      Code:
      import java.sql.*;
      class RecordFetcher
      {
      	Connection cn=null;
      	Statement stmt=null;
      	ResultSet rs=null;
      	RecordFetcher()
      	{
      		try
      		{
      			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      			cn=DriverManager.getConnection("jdbc:odbc:mydsn");
      			stmt=cn.createStatement();
      			stmt.setMaxRows(10);
      			rs=stmt.executeQuery("select * from test");
      			while(rs.next())
      			{
      				System.out.println(rs.getString(1)+" "+rs.getString(2));
      			}
      		}
      		catch(Exception e)
      		{
      		}
      	}
      	public static void main(String args[])
      	{
      		new RecordFetcher();
      	}	
      }

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        I'm not sure if it's supported, but can you add

        "LIMIT 10 OFFSET 10"
        to your query string?

        Or have you looked at getMoreResults( )?

        Comment

        Working...