• 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

Statement.executeQuery fails --RESOLVED--

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic