Re: Attribute 'name' not found ERROR for postgres and java

From: Steve Waldman <swaldman(at)mchange(dot)com>
To: suhail sarwar <sarwar(at)postmaster(dot)co(dot)uk>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Attribute 'name' not found ERROR for postgres and java
Date: 2001-04-28 20:10:31
Message-ID: 20010428161031.A18265@peanut-butter.mchange.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Sarwar,

Your problem is in either in your SQL syntax or in the use of prepared
statement, depending on what you wanted to happen.

The error you are seeing comes because "name" in your SQL statement
is neither the SQL String literal 'name', nor any kind of variable
or identifier Postgres knows about. Yes, it is the name of the column
you are trying to insert in, but that does not help postgres figure
out what you are trying to insert.

If you intended to insert the literal 'name' into the table, modify
your code like so:

PreparedStatement stt = db.prepareStatement("INSERT INTO Test1 " + "VALUES (100, 'name', age)");
stt.executeUpdate();

If name is a variable which you intended to have inserted into the
table, try this:

String name = "Sarwar";
PreparedStatement stt = db.prepareStatement("INSERT INTO Test1 " + "VALUES (100 , ? , age)");
ps.setString(1, name);
stt.executeUpdate();

Hope this helps,
Steve

On Sat, Apr 28, 2001 at 12:58:54PM +0100, suhail sarwar wrote:
> Hi,
>
> I am getting this sql exception "Attribute 'name' not found" and I can't seem to figure it out at all. I have a java program that creates a table in postgresql using a prepared statement and that bit works. Then I have added another prepared statement to populate the table with values (see below):
> PreparedStatement stt = db.prepareStatement("INSERT INTO Test1 " + "VALUES (100, name, age)");
> stt.executeUpdate();
>
> There is a column in the table Test1 called name but it is unpopulated and the above code should insert the values. However I get the sql exception attribute name not found.
>
> If I change 'name' in the above code to say 'neat' then the sql exception changes to "sql exception attribute 'neat not found".
>
> Does anyone know what is happening.
>
> Any help is much appreciated.
>
> Regards
>
> Sarwar
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Albert REINER 2001-04-28 20:33:53 Re: Attribute 'name' not found ERROR for postgres and java
Previous Message tompoe 2001-04-28 15:03:23 Re: install question