Re: Java.sql.SQlException



On 31 Oct, 11:27, David Harper <devn...@xxxxxxxxxxxxxxxxxxx> wrote:
Clive_ wrote:
I am trying to get an SQL statement to check that the users ID and the
ID row in a table match. There maybe up to a hundred users using the
database.

I have two tables in SQl Server express - Users and Property1 both
with a
SurveyID column ie Users.SurveyID and Prop1.SurveyID

The SQL statement is:
String querySQL=("Select * from Prop1_WallFinish where SurveyID =
\"Users.SurveyID\"" );

I am getting a java.sql.SQlException: Invalid column name.

Could anyone point out what is wrong with the statement???

It looks to me like you have two problems.

First, your select statement is trying to select from a table named
"Prop1_WallFinish" rather than from either of the tables you mention,
Users and Property1. Perhaps you actually mean

select * from Property1 ....

Second, your "where" clause looks fishy. Assuming that you really mean
to select rows from the table named Property1, then your query appears to be

select * from Property1 where SurveyID = "Users.SurveyID"

which is testing an ID column, which is presumably a number, against a
literal string "Users.SurveyID".

Are you trying to match rows in the Property1 table which have the same
SurveyID column as rows in the Users table? That's called a join. It's
a very common type of query, but the syntax is different than what
you're trying to use.

May I suggest that you read the documentation for your database system
and pay close attention to the chapter which explains joins. It will
tell you how to query across two tables. Use your database system's
command-line query tool to talk directly to your database server and try
out various different queries before you take the leap to programming
them in Java. One hurdle at a time ... :-)

David Harper
Cambridge, England- Hide quoted text -

- Show quoted text -

Hi David,

Thanks for email.

I do not want to create a inner or outer join. I want to make sure
that the UserID match in both tables. To ensure the user enters data
into the correct row.

clive

.



Relevant Pages

  • Re: Java.sql.SQlException
    ... First, your select statement is trying to select from a table named "Prop1_WallFinish" rather than from either of the tables you mention, Users and Property1. ... Are you trying to match rows in the Property1 table which have the same SurveyID column as rows in the Users table? ... It's a very common type of query, but the syntax is different than what you're trying to use. ... May I suggest that you read the documentation for your database system and pay close attention to the chapter which explains joins. ...
    (comp.lang.java.databases)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: OT: SQL
    ... query processing. ... FROM Employees e, Employees m, Management mgt ... Manager and Employee Salaries. ... The scheme used does not model database files in general, ...
    (sci.logic)
  • Re: access 2003
    ... I removed the parameters from the form query source. ... boxes from the form header, events, code, etc and ran the form query source ... forms queries and the SQL because syntax of the SQL will change randomly. ... the Access 97 database, I wouldn't have thought any expressions would be ...
    (microsoft.public.access.conversion)
  • RE: Import external data - web query
    ... Your reply for my query is very extensive, this is for importing a file from ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)