• 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

Retrieving result from a result set

 
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a piece of code


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
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try checking the databases where you are running SQL manually and through JDBC are same.

Regds,
Amit
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
amit


my database gives me the correct result .
My database table has columns as :-
Sno,SessionId,Count_logins,usename

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:-
rs.getInt("log");
and it shoukld return me the value in the column named log
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay,
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

regds,
amit
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ragi singh wrote:my database gives me the correct result


How are you checking the results of your query ? Which tool are you using ? How do you login ? Which user ? Which schema ? Please clarify all these.
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christophe

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 .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not answering all my questions. I'm not asking for the table layout.
So, with Sql Developer, which user, which password, which schema are you login in to ?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Can you post the connection string that is being used in SQLDeveloper?

Regds,
amit
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

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 .

Thank you folks .
 
reply
    Bookmark Topic Watch Topic
  • New Topic