GeeCON Prague 2014*
The moose likes JDBC and the fly likes Statement.executeQuery fails --RESOLVED-- Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Statement.executeQuery fails --RESOLVED--" Watch "Statement.executeQuery fails --RESOLVED--" New topic
Author

Statement.executeQuery fails --RESOLVED--

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Oh God. Thank you God. I solved the problem by enclosing the column name in quotation marks "SELECT * FROM document WHERE 'reassign_documents_primary_key_col'=2". IT IS AN UNBELIEVABLE MYSTERY.


In the code below, the line is throwing an SQL exception : "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."

The problem is that the code works for many tables:
SELECT * FROM user
SELECT * FROM control
SELECT * FROM document
SELECT * FROM document WHERE assigned_documents_primary_key_col=2
SELECT * FROM document WHERE initiated_documents_primary_key_col=2

But fails for "SELECT * FROM document WHERE documents_to_assign_primary_key_col=2". The exact same string executes directly in MS Access and the column documents_to_assign_primary_key_col exists in the table.

There is more to the problem: If I run a static method from a test class calling the method getObjectsRowSet above, everything works fine.


When this runs I get
SELECT * FROM user
SELECT * FROM control
SELECT * FROM document
SELECT * FROM document WHERE assigned_documents_primary_key_col=2
SELECT * FROM document WHERE initiated_documents_primary_key_col=2
SELECT * FROM document WHERE reassign_documents_primary_key_col=2
Success


Your help will be greatly appreciated,
Alejandro Barrero
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Usually Access produces that extremely helpful message when a table name in your query is not in the database, or when a column name is not in the table. Sometimes people forget to put quotes around a string constant, in which case Access will assume that string is the name of a column.

And sometimes people say that "the exact same string" works in one place and another, when they typed it correctly in the one place and incorrectly in the other.

What I'm trying to say here is, your SQL statement is incorrect. It looks to me like it would be very easy to misspell those column names without noticing.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Thank you for your help Paul. However. I have verified that the names are correct and that I use in Access the exact string that fails with JDBC; I print to the standard output the string that the program uses and I copy and paste to run it in Access. The last thing I did was to change the name of the column, but I still have the same problem. You just gave me the idea to write a test program to see if there is any problem with the sequence of the statements or something else.
 
GeeCON Prague 2014
 
subject: Statement.executeQuery fails --RESOLVED--