File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Conditional select statement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Conditional select statement" Watch "Conditional select statement" New topic
Author

Conditional select statement

nuts peanuts
Greenhorn

Joined: Jun 22, 2004
Posts: 1
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

Joined: Jun 10, 2004
Posts: 53
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.


Best Regards<br />N.Shankar<br />SCJP, SCWCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

"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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
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:


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Conditional select statement
 
Similar Threads
encrypted username breaks sql
My sql query returns zero rows
No errors but no update on table
oracle.jdbc.driver.OracleDriver cannot be resolved to a type
Adding parameter on select statement