• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Field not found - need help on code

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I need help with the following sql in my java app:

The above sql works great when it finds the 'barcode' field in the DB, but when it doesn't find the field then I want to make a prompt appear on the screen for the user.
How can I do this without using the rs.next()-false method?
Any help much appreciated.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suhail,
I can only give you a partial answer, which is based on the way that SQL works, you'll have to get the rest of the answer on how to do this in JAVA, from another source. However, I can at least give you enough information to help compose a question to that other person. I also hope that I'm not insulting your intelligence with this reply, please forgive me if I am over simplifying.
First, when using the LIKE predicate, one has to be sure that you know that this is a pattern search process and not looking for and exact match (equality), which is a different predicate. Therefore, the pattern being used should contain either the underscore "_" which means look for any single character in that position, or use the percent sign "%", which means look for any number of characters (even zero characters) of any character in that position coded in the pattern.
Additionally, be aware of the fact that the non-pattern characters included in the string ARE case sensetive.
Where lastname LIKE '%SON'.
Will find: JOHNSON, ANDERSON, WESSON, and so on.
It will NOT find: johnson, anderson, ... and so on because of the case.
Secondly, some DBMS (Data Base Management Systems) don't use the % or _, but other characters, you'll have to check their doc for confirmation.
Thirdly, the test for whether or not the query finds any results will depend on the implementation of how you search. When I code non-Java programs (because I'm going through a great learning curve in JAVA and it's quite new to me), in other languages and platforms, I test for the results to come back from the server in either SQLCODE or SQLSTATE.
SQLCODE is a large integer, SQLSTATE is a character (5) field, both return a value that describes what happened in the last SQL statement you executed.
SQLCODE = 0 -- everything worked ok
SQLCODE < 0 -- an error, probably with some diagnostics
SQLCODE > 0, but not +100 - an SQL WARNING (it worked, but it wants to tell you about it with a qualification, usually, not to worry)
SQLCODE +100 - no more data to be returned (like end of file condition) or no data found in the first place.
SQLSTATE '00xxx' -- Unqualified success.
SQLSTATE '01xxx' -- Warning
SQLSTATE '02xxx' -- No data returned,
Then there are bunches of other prefix codes that imply all kinds of categories of errors.
I'd recommend test for the code then determine, in the logic of your program to issue the prompt... now, I return you back to your JAVA code issue.
Regards,
Gary J.
Colo Spgs, CO
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suhail if u use rs.first() it will move the cursor to the first row and will return false if there is no row in the resultset i.e. empty resultset.
Hope that helps
Gul
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also introduce a flag in your code to check if there are any rows in the resultset coz u have to use rs.next() anyway here is how i do it.
boolean flag=false;
while(rs.next()){
flag=true;
}
if(flag==false)
System.out.println("There are no barcodes available");
 
reply
    Bookmark Topic Watch Topic
  • New Topic