I tried everything you suggested. 'Think it is the way I have set up 
the table in MYSQL. This is the table 
   
  +------------+---------------+------+-----+---------+-------+
| Field      | Type          | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+-------+
| ssn        | int(9)        |      | PRI |         |       |
| submitdate | date          | YES  |     | NULL    |       |
| submitto   | int(3)        | YES  |     | NULL    |       |
| first      | varchar(30)   | YES  |     | NULL    |       |
| last       | varchar(30)   | YES  |     | NULL    |       |
| loanAmt    | decimal(10,2) | YES  |     | NULL    |       |
| company    | int(3)        | YES  |     | NULL    |       |
| fee        | decimal(10,2) | YES  |     | NULL    |       |
| appType    | int(3)        | YES  |     | NULL    |       |
| appSource  | int(3)        | YES  |     | NULL    |       |
| appStatus  | int(3)        | YES  |     | NULL    |       |
| dateStatus | date          | YES  |     | NULL    |       |
| fundedAmt  | decimal(10,2) | YES  |     | NULL    |       |
+------------+---------------+------+-----+---------+-------+


Hassan Schroeder <[EMAIL PROTECTED]> wrote:  On 1/2/07, murthy gandikota wrote:

> ps = con.prepareStatement("select first, last from cust where ssn=?");
> int ssnint = Integer.parseInt(ssn.trim());
> ps.setInt(1, ssnint);
> ResultSet rs=ps.executeQuery();
> if ( rs.next()) {
> rs.close();
> out.println("Customer already exists " + Integer.parseInt(ssn));
> return;
> }

> I get the message "customer already exists" for EVERY ssn that I tried.

Not sure how you're actually running this, but it looks dangerous -- if
rs.next() is false, you're not closing that ResultSet object. And the `return`
seems pointless here. What happens if you change that 'if' to 'while', and
print out the first, last, ssn results? (and for good measure change that
SELECT statement to 'SELECT ssn, first, last').

For comparison, here's some simple code similar to yours, which works
exactly as expected: if "messageId" doesn't exist in the DB, it prints out
the "not a valid id" message.

stmt = conn.prepareStatement("SELECT messageText FROM messages WHERE
messageId = ?");
stmt.setInt(1, id); 

rs = stmt.executeQuery();
if ( rs == null )
{
out.println("null ResultSet
");
// never happens :-)
}
if (rs.next())
{
out.println(rs.getString(1) + "
");
}
else
{
out.println("not a valid id");
}
rs.close();
stmt.close();
conn.close();

HTH,
-- 
Hassan Schroeder ------------------------ [EMAIL PROTECTED]


 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to