but i am unable to fetch the correct result from database . I am always getting the value 4 in count , however in my database the value for MAX(count_logins) is 2 . Can anyone explain how i can get the right value from my resultset
my database gives me the correct result .
My database table has columns as :-
Can we use alias in the query and use the same alias for a column when using the result set .I mean in my case the alias is
log so can i use result set as:-
and it shoukld return me the value in the column named log
Joined: May 14, 2004
I meant to say
1) Check the database instance(IP and SID) that gives you count - 4 as result - this is the one which you are using in JDBC program
2) Check the database instance(IP and SID) that gives you count - 2 as result - I think you are checking this manually running the SQL
My table name is sessions:-
and the table structure is as follows:-
Sno Number(30), Session_ID Varchar2(4000),Count_logins Number(30),Usename Varchar2(30)
and I am using sql developer for querying the database . I have used oracle database . Each time i loop in rs.next() loop the values for count are abnormal also result set displays more rows than in the table itself . I cannot understand the abnormal behaviour of result set .
I am sorry for being late in reply . I got my question solved , actually I changed my code as follows:-
My original code :-
Thinking that the code coming from database is ordered in the way the rows were inserted . However my data coming from the database was in some random order . Every time a user logged in all the rows were retrieved from the database . So if the third user logs in my result set was giving me three records . I wanted the last record inserted as it contained the field which holds the latest value of a count variable (number field) . So my res_count variable was holding any of the three values (whichever was retrieved last ) that is why my result was inconsistent . So I changed my code as:-
In this case my res_count always holds the last (greatest value of count ) which is what i want . So i am able to get consistent result and my doubt gets solved .