Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Result set is empty

 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have checked in Sqlplus there are two entries in the table login. It does not go into the loop while(rs.next());

How do I fix this so it works?

Thanks,

Sonia
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do this, what do you get?

 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot do that. I have to use the connection and stmt to execute a query to the database.

THanks,

SOnia
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"System.out.println" has nothing to do with the DB - it serves as a debugging aid. The point Edwin was trying to make is that you should check what the actual query looks like that gets sent to the DB.

As a side note, it is much better to use a PreparedStatement than to construct the query on the fly using string concatenation. Amongst other benefits, it makes sure that the code isn't susceptible to SQL injection attacks.
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The examples on prepared statements are not that complete.



Is this good? The print statement for the query gives me the following without a semicolon:

and n=0;

Thanks in advance,

Sonia
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you run that query directly against the DB? Are you getting results returned?
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes; i get results.

Sonia
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code are you sure you are connecting to the same database which contains these records?
 
sonia pandit
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was a matter of case. I changed the column to uppercase and it works. I did not realize SQL was case sensitive.
I also changed it to use Prepared Statement. Now somebody has adviced me to use Hibernate and Spring. So I have to research that. Sure I will be posting questions with that.

Thanks,

Sonia
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic