Re: Two of three SQL stmts execute: third results in table does not exist exception



On Mar 16, 3:09 am, David Harper <devn...@xxxxxxxxxxxxxxxxxxx> wrote:
GGP wrote:
I attempt to collect data from a database three times in one method,
all using one connection. The first two queries execute without any
problem. However, the third fires an sql exception:

java.sql.SQLSyntaxErrorException: Table/View 'TABLENAME' does not
exist.

I connect to the database using a connection class, as follows:

[SNIP]
ResultSet rs3 = null;
Statement stmt3 = null;
stmt3 = con.createStatement();
String sqlListData = "select " + unitID + ", " + unitName + "
from " + tableName;
rs3 = stmt3.executeQuery(sqlListData); //This is where the
error occurs. All the strings in stmt3 are fine (correct spelling,
etc.)

[SNIP]
Any ideas? I really appreciate the help.

You do not show us how the variable "tableName" has been defined, so it
is almost impossible to offer advice.

However, I'm guessing that somewhere in your code, you have set

String tableName = "TABLENAME";

Perhaps you intended to set the correct value elsewhere in your code,
but you forgot to do so. Since we can't see the rest of your class
definition, it's impossible to say for sure.

David Harper
Cambridge, England

David,

Thanks for the reply. Yes, I do set TABLENAME almost as you suggest.
The difference is that I have to construct the name by extracting the
root from one of the previous two queries and concatenating a suffix.
For example, all my table names end with "CF" and one of the tables
may relate to 'mass' (info extracted from one of the other queries).
In that case, TABLENAME would actually be "MassCF". The variable
definition is there in the code, and is:

String TABLENAME = strRoot + "CF";

The actual table "MassCF" does exist and spelling is correct (in both
the code and actual table names). During the debugging process, I
checked to see if names were being generated properly, and they appear
to be fine (which is why I suggested that the first two queries
worked). I'd be happy to provide the full class definition if you
think it would help.

Thanks again for your help,

Greg.

.



Relevant Pages

  • Re: Exporting 2 queries into 1 excel spreadsheet
    ... UNION the queries together, then export. ... Select * from tablename ... Professional Access Database Repair ... to save the excel spreadsheet and what to save it as. ...
    (microsoft.public.access.queries)
  • Re: Help with Concatenated / Nested Query results
    ... > meant to place it in queries. ... > Mary Doe, Marty Doe, Jimmy Doe, Lonnie Smith - State Farm ... helping people with Access reporting solutions. ...
    (microsoft.public.access.queries)
  • Re: A question about efficiency
    ... > Although I can optimise my queries and my PHP scripts, ...
    (comp.lang.php)
  • Re: PHP strange error with MY_SQL database
    ... > able to execute select, update and insert queries, however I am getting ... > set returned is empty (for queries other than select). ... indent your code before pasting it to the newsgroups. ...
    (comp.lang.php)
  • Re: Can you search a table name in queries?
    ... I need to be able to type a tablename into a box, and search my entire database to see which queries are using that table. ... sub testing ...
    (comp.databases.ms-access)