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 sql error 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 "sql error" Watch "sql error" New topic

sql error

Ian Cockcroft
Ranch Hand

Joined: Apr 05, 2001
Posts: 46
Hi guys, the following function accesses an access data base and returms a boolean (Yes/No in access) and is supposed to populate and return a boolean array. For now I am just testing the sql, but it is throwing the exeption. Anyideas why and ow would I return a boolean array from the function.
Thanks guys.

ps. sorry about the code formating, couldnt get it right

(Use spaces rather than tabs. Formatting will be better -- Marilyn)
[ July 10, 2002: Message edited by: Marilyn de Queiroz ]

- Make it idiot proof and they'll make a better idiot!
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
What exception are you getting? Is it a runtime exception? Or compile time? If you uncomment the return statement at the end, it won't compile because you're trying to return something from a method declared as void.
To return an array of booleans just declare the method like this:
public boolean[] getUserAccess(String strUserName) throws Exception {
In the method you have a long SELECT statement commented out, I assume you're using the shorter one just to test, if not then when you execute another query on the Statement stmtAccess you'll close the first result set. Also, there is no FROM clause in the test SQL.
Nowhere in the code do you populate the array either. If you are going to do it in the loop in the code then you'll have to make sure you dont exceed the 11 entries you allocated for it.
Another thing, it's been a while since I used Access, but I dont think you can get a boolean from it. It uses a field it calls Yes/No which I dont think is a true boolean. You might have to get a result and see how it is returned to determine how to handle it.
Hope that helps a little bit, the biggest thing right now is to tell us what the exception is your getting. If it a runtime exception and you catch it then print out the message and the stack trace for it.

Ian Cockcroft
Ranch Hand

Joined: Apr 05, 2001
Posts: 46
Hi Dave, top drawer. Thanks alot. The error was because there was no FROM clause.
I have finished it and it looks like this:

Thanks once again
[ July 10, 2002: Message edited by: Ian Cockcroft ]
I agree. Here's the link:
subject: sql error
It's not a secret anymore!