java - Cannot find item in database when one column is null -


i have program requires me input id of product , search database in order display details specific product.

the code works fine every item in database except productid 2 , productid 4 because have no data stored in 1 of columns (product_type).

i've got if statement in code says:

else if (result.getstring("product_type") == null && result.getstring("description ") == null) { system.out.println("item id: " + result.getstring("stockitem") + ". \nproduct name: " + result.getstring("product") + ". \ncost: £" + result.getstring("cost") + ". \nstock level: " + result.getstring("stocklevel") + ". \nproduct type: null."); } 

but cannot figure out why it's unable find product if product type null can still find if description null.

    try{                 string searchcode = "select products.product, products.cost, products.description, product_stock.stockitem , product_stock.stocklevel product_type inner join (products full outer join product_stock on products.productid = product_stock.stockitem) on product_type.prodtypeid = products.product_type productid = " + inputvalue + ";";         // sql statement searches database required data          statement statement = dbconnection.createstatement();         resultset result = statement.executequery(searchcode);         boolean found = false;         found = result.next();          if (!found) { //if no data found display error message , restart product search method             system.out.println("that product couldn't found, please try again.");             searchproduct();         }         else if (result.getstring("product_type") == null && result.getstring("description ") == null)         {             system.out.println("item id: " + result.getstring("stockitem") + ". \nproduct name: " + result.getstring("product") + ". \ncost: £" + result.getstring("cost") + ". \nstock level: " + result.getstring("stocklevel") + ". \nproduct type: null.");         }         else if (result.getstring("product_type") == null && result.getstring("description") != null){             system.out.println("item id: " + result.getstring("stockitem") + ". \nproduct name: " + result.getstring("product") + ". \ncost: £" + result.getstring("cost") + ". \nstock level: " + result.getstring("stocklevel") + ". \ndescription: " + result.getstring("description") + ". \nproduct type: null.");             }         else if (result.getstring("product_type") != null && result.getstring("description") == null){                 system.out.println("item id: " + result.getstring("stockitem") + ". \nproduct name: " + result.getstring("product") + ". \ncost: £" + result.getstring("cost") + ". \nstock level: " + result.getstring("stocklevel") +  ". \ndescription: null. \nproduct type: " + result.getstring("prodtype_desc") + ".");             }         else if (result.getstring("product_type") != null && result.getstring("description") != null){             system.out.println("item id: " + result.getstring("stockitem") + ". \nproduct name: " + result.getstring("product") + ". \ncost: £" + result.getstring("cost") + ". \nstock level: " + result.getstring("stocklevel") + ". \ndescription: " + result.getstring("description") + ". \nproduct type: " + result.getstring("prodtype_desc") + ".");             }         }     catch (exception e){ // if product can't found display error message , restart product search method         system.out.println("could not find product.");         system.out.println(e.tostring());         searchproduct();     }      //goes menu once method has finished     askuser(); } 

any massively appreciated. thanks.

do have typo?

result.getstring("description ") == null

should be

result.getstring("description") == null

note space in "description " in current version.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -