This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Problem with the query in JDBC ,resultset empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with the query in JDBC ,resultset empty" Watch "Problem with the query in JDBC ,resultset empty" New topic
Author

Problem with the query in JDBC ,resultset empty

Bhavik Patel
Ranch Hand

Joined: Jul 12, 2004
Posts: 155
i am using chkUser() to check the user's existence in the database.
its also trying to fetch and set all the values for student eg email,phone while fetching the username and password...in both rs1 and rs2 if i set query with just UNAME = 'CHIRAG' then its giving me the result but
it doesn't give me reuslt with UNAME='CHIRAG' AND PASSWORD='chirag'...Is it that it doesn't support AND keyword..... with both UNAME and PASSWORD its giving me following output.....there is one row in database that has UNAME='CHIRAG' and Pasword='chirag' but it gives me rs empty ...not null

I am getting output

errorcode -1
at last errorcode -1


Following code.....
i am calling chkuser() which calls getStudentInfo()



[edited to add code tags]
[ April 12, 2005: Message edited by: Jeanne Boyarsky ]

SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Bhavik,
Why are you doing the query in two steps instead of one?

In any event, try the following query:
ResultSet rs1=stmt.executeQuery("SELECT SID, UNAME, PASSWORD FROM STUDENT WHERE UNAME like '%C%' AND PASSWORD like '%c%'");
This will help narrow down whether there is a typo. The "and" is very straightforward and not the problem. Also, note that the username and password values are case sensitive, so double check that.

Finally, note that the result set will never be null. JDBC drivers return an empty resultset, but not null. So that piece of code is extraneous.


[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
 
 
subject: Problem with the query in JDBC ,resultset empty
 
Similar Threads
Problem in returning the username
packages --- Not allowing me to access public class from the same package...
accessing one class from other
SQLException : not all variables bound
incrementing numbers in database when a new object is added