Обсуждение: Attribute 'name' not found ERROR for postgres and java

Поиск
Список
Период
Сортировка

Attribute 'name' not found ERROR for postgres and java

От
"suhail sarwar"
Дата:
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
programthat creates a table in postgresql using a prepared statement and that bit works. Then I have added another
preparedstatement 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.
HoweverI 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

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

От
"Albert REINER"
Дата:
I don't think this has anything to do with the java part; you'll
probably see the same with psql alone.

I guess you really want to do something like

insert into test1 (name, age) values ('Granma', 100);

if name and age are the names of the columns you want to set. Note the quotes
for the string.

HTH,

Albert.

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
programthat creates a table in postgresql using a prepared statement and that bit works. Then I have added another
preparedstatement to populate the table with values (see below): 
> PreparedStatement stt = db.prepareStatement("INSERT INTO Test1 " + "VALUES (100, name, age)");
...

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

От
Steve Waldman
Дата:
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
programthat creates a table in postgresql using a prepared statement and that bit works. Then I have added another
preparedstatement 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.
HoweverI 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
notfound". 
>
> 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