• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to retrive the data of the last row in the table ?

 
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
munjal upadhyay
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please do not consider compilation error
because I had cut a part of the program from the hole program...
 
munjal upadhyay
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think its of the jdbc type .
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you haven't sorted the query, the "last" row doesn't really have meaning. It's an artifact of how the data is stored. The easiest way to get the last row is to make it the first row. For example query
.

Then you can call if ( rs.next() ) and rs.getString(1).
 
munjal upadhyay
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:As you haven't sorted the query, the "last" row doesn't really have meaning. It's an artifact of how the data is stored. The easiest way to get the last row is to make it the first row. For example query
.

can you please tell me , how to get the data of a perticular row ?
(write a querry if possible)

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to fetch only the last row, you can use 'limit', like this.with this query, you can fetch the whole record. if you want to fetch only the last ID, you can try using aggregate function. like thisassuming the column is an integer
 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use result.last(), to point to the last row and then get its values
 
munjal upadhyay
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I got the last row now ,

but the priblem is that I am not getting the data of the perticular row..

my Table names Table1 has three fields -> ID,Name,SName

I write the querry
result =state.executeQuery(" SELECT * FROM Table1 WHERE ID=3 ");
then I print that

System.out.println("Name is "+result.getString("UserName"));
System.out.println("SName is "+result.getString("Surname"));

but,,
the exception dispayed as follows...

[Microsoft][ODBC Driver Manager] Invalid cursor state

I have already 15 data in the Table1.
so , what happening ?
 
munjal upadhyay
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vic Hood wrote:You could use result.last(), to point to the last row and then get its values




the result.last() only not work
I got it..

we have to change

Statement state = c.createStatement();
to
Statement state = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic