how to get a specific row values from database using servlet?(without using any sql conditions.)
I want to display a table from a database. However I only want开发者_如何转开发 to display 5 rows (from 6th to 10th) only given the name of the table.
It is a dynamic process, so the query doesn't depend on the table values.
If I understand your question, you will use the "select * from tbname limit 5".
On a second thought doing this will give you the first 5 value based on your search criteria, if this is what you want. So you still need to be clear about your search criteria.
Firstly there is no such thing as "first" in a table. You need to impose your idea of firstness using the " ORDER BY " clause.
In your case I would select whatever you want from the table order by whatever you think "first" means and simply loop past the first five rows.
SELECT NAME, AGE, SCORE FROM GAMERESULT ORDER BY SCORE
You can use the command limit for example you can say:
select * from table a limit 5,10
@mariana soffer is correct but it fetches from row no 6 to 15 also it can be used only with some database like mysql for other databases see http://en.wikipedia.org/wiki/Select_%28SQL%29#Result_limits
select from table name limit n
Where n
is the number of rows you want to fetch.
I think this will work.
精彩评论