[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

result set null

I am working with servlets database connectivity.
I have a table in the dtatabse where only usernames and passwords r stored. I want to give an error message if the user is not at all presnt, ie, he is a new user.
the query is 'select * from table where username = 'user';
how to check for the null resultset ?,  
result.wasnull() checks only whether the last column read had this special value.
pls explain me with the code

the other question is can 2 or more than 2 queries can be run simultaneously. like depending upon the result set values of one query the other query should run.
can this be possible ?
Pls explain.
0
pbhag
Asked:
pbhag
  • 3
  • 3
1 Solution
 
JodCommented:
Create your statement object then execute your query like this:

ResultSet rs = stmt.executeQuery ("select * from table where username = 'user'");
if (rs.next())
{
  System.out.println("Found at least 1 matching record...");
} else {
  System.out.println("Found no matching records...");
}


However, in general the best way to do this is to actually ask SQL to return you an integer which is the count of matching records - this will always return a value which will be 0 if no matches were found or more than 0 if there were. You do that like this...

ResultSet rs = stmt.executeQuery ("select count(*) from table where username = 'user'");
while (rs.next())
{
  System.out.println("Found " + rs.getInt(1) + " matching records...");
}


If you are just running one query after another then you should get no real problems as long as the queries do not update or overlap into the same data.

Whether you can run two concurrent queries depends on whether your database driver supports it - the JDBC-ODBC bridge will not guarantee to work.
0
 
pbhagAuthor Commented:
hey thanks Jod, its working now,
I should have used if instead of while (result.next())
Now its perfectly woking.
Thanks

but in the second one, I am still getting the probs, since the second query runs only if the result got from the first query matches with some particular value, so I need to run that query within the another.
0
 
JodCommented:
What exactly is the query you are trying to perform? You can perform conditional queries within SQL or Java so I would need to know what it is you are trying to achieve.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
pbhagAuthor Commented:
Adjusted points to 100
0
 
pbhagAuthor Commented:
am a colleague of priya,she has left us,so grading it myself,damn cookies.
:-)

Guess who ,u no me ,Jod
0
 
JodCommented:
Personally I LOVE cookies. Mmmmm, chocolate chip.

But who are you?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now