This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement.executeQuery fails --RESOLVED--

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • 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

 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 335
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic