File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Field not found - need help on code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Field not found - need help on code" Watch "Field not found - need help on code" New topic

Field not found - need help on code

suhail sarwar

Joined: Mar 15, 2003
Posts: 4
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 method?
Any help much appreciated.
Gary Joehlin

Joined: Sep 18, 2003
Posts: 16
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.
Gary J.
Colo Spgs, CO
Gul Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
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 Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
You can also introduce a flag in your code to check if there are any rows in the resultset coz u have to use anyway here is how i do it.
boolean flag=false;
System.out.println("There are no barcodes available");
I agree. Here's the link:
subject: Field not found - need help on code
jQuery in Action, 3rd edition