Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the query returned more than one line

 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
if the query returned more than one line, how can i go line by line ?
i use this :

when, i put this statement "SELECT user_id,user_password,user_role from users " in the tool of postgres it display a table with two line.
I want to go line by line, could you please tell me how can i do this ?
thank you in advance
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't know why only the one value from table is retrived !!!
I'm really stuck
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue.

I'm not following - the while loop processes the result record by record, and it sounds like that is what you want to happen. So what does happen exactly, and how is that different from what you would like to happen?

Edit: I see, the JDBC code retrieves only a single record, whereas the direct query retrieves two. I didn't get that from your original post.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i retrive the two line of the table
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know that only a single record gets retrieved? As I said before in the other thread where you asked about this (don't do that, by the way, we don't want several topics for the same question) there is no code path that would ever allow the second iteration of the while loop to be run.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other question is different to this, is about a problem in my login page that display an exception "java.lang.IllegalStateException: Unable to use'' do-follow (forward) after the response has been" and i solve it.
Here, my problem is how can i go in my result line by line.
I debug my application in eclipse and it's a single record
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way you get ever get to the second record is of the the first record matched ID and password, but the role was neither employee or admin; is that the case?

Have you tried it while having commented out all the redirects?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only the first line is detected.
I will try with commented out all the redirect and i will tell you the result
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i just change my code to this :

and i run it with a valid name and valid password but the role is an employee
see what i get in the console :

knowing that in my users table i have 3 line : first is an admin, second is an employee and third is an employee.
So, here he go line by line in the table, so it's work.
The problem is how to go to other jsp page in every condition?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is how to go to other jsp page in every condition?

Not following. What prevents you from performing different actions for the different cases?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what's the solution according to you ?
use sendRedirect is not the correct way
i need your help, than k you in advance
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you want to do a redirect, then sendRedirect *is* the right way, but you need to to use only in the right circumstances.

The problem with your latest code is in line 49 -which you have now commented out- you're redirecting no matter what, thus preventing the second (and subsequent) record from ever being read. You should only do the redirect after you have established that the login credentials are incorrect for ALL records.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:You should only do the redirect after you have established that the login credentials are incorrect for ALL records.

Did you have any idea how can i do this ?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do the redirect to the failure page in the loop - there might be a valid record still to be read. So you need to do it after the loop has finished.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply, i will try as you told me
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, should you please tell me what's wrong now ?
here's the new code :

thank you in advance
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly does that code do, and how does that differ from what you expected to happen?

It seems to assign something to "value" during each loop iteration, and that seems wrong. If it assigns 1 or 2 in the first iteration, and then 3 during the second iteration, would the right thing happen?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In principle, I found the solution
what is your opinion about this code?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by "in principle" - does the code work, or does it not work? As I sad, I suspect that it does not work reliably - the order in which records are returned from the DB makes a difference, and since SQL does not guarantee that order, the code looks potentially broken to me.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, it's work.
the code looks potentially broken to me.

What do you mean by this statement ?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Earlier you had an example where the DB would return 3 records, resulting in output of "nothing", "employee", "nothing", successively. Would this code work correctly in that situation?

Edit: Never mind, I had missed the "break" statements you added for cases 1 and 2. With those in place, the code looks OK.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thank you
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another question about this servlet but not in this forum, should i ask it here ?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a new question, not JDBC related, then please post it as a new question in the appropriate forum (such as Servlets).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic