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