File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to retrive the data of the last row in the table ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to retrive the data of the last row in the table ?" Watch "how to retrive the data of the last row in the table ?" New topic
Author

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

munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69

munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69

please do not consider compilation error
because I had cut a part of the program from the hole program...
munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69

I think its of the jdbc type .
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

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).


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69

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)
Sharath Upadhya
Greenhorn

Joined: Dec 01, 2009
Posts: 9
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
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

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


Learning and Learning!-- Java all the way!
munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69


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

Joined: Sep 18, 2010
Posts: 69

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.
 
subject: how to retrive the data of the last row in the table ?