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

Conditional select statement

 
nuts peanuts
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a code that queries the database to get information about a bank customer,by comparing the Username and Pin.
If they match then his balance is shown to him.
else I want him to prompt for a corrct name and PIn.

PreparedStatement stmt = con.prepareStatement("Select * from BankAccount where DbUserName = ? and DbPin= ?");

stmt.setString(1,UserName);
stmt.setString(2,Pin);

ResultSet rs = stmt.executeQuery();

Now If the username or pin is wrong the rs is nulll....
So how do i prompt for a Correct Pin and Username...In a catch for null pointer???
 
Natarajan Shankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nuts,
Just b4 iterating rs you can check for null right? any issues in it, or I havn't understood the issue as you meant.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"nuts peanuts",

We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now If the username or pin is wrong the rs is nulll....
Actually, if your query returns no rows, your ResultSet will not be null, rather a call to rs.next() will return false.

So, you test for that something like this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic