Обсуждение: column not found !

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

column not found !

От
Savio Domnic
Дата:
Hello,
I am trying to retrive a record from pqsl DB using the
following steps.

First I prepare a String Buffer "prepareSql".

prepareSql.append("Select");

    if(req.getParameter("firstname") != null){
        prepareSql.append(" name,");
    }
    if(req.getParameter("city") != null){
        prepareSql.append(" city,");
    }
    if(req.getParameter("zip") != null){
        prepareSql.append(" zip,");
    }
    if(req.getParameter("country") != null){
        prepareSql.append(" country,");
    }
    if(req.getParameter("email") != null){
        prepareSql.append(" email,");
    }
    // Deleting the Coma at the end of an entity.
    int sbLength = prepareSql.length();
    prepareSql.deleteCharAt(sbLength - 1);

    prepareSql.append(" from Personal where immat = " +
Integer.parseInt(req.getParameter("immat")));
return prepareSql.toString();

Second I pass this string to a method thru a variable
"sql" and execute this statement.

stmt.executeQuery(sql);

To my information I did a System.out.println(sql);
and I got the result "Select name, zip, email from
Personal where immat = 500103"

I get the error "The column name immat not found." as
the SQL Execption.

I executed the same statement in the psql command line
it was executing it and displaying the record.

Can someone explain me what wrong I had made. I had
also attached the codes for your reference.

Thanks in advance.
Domnic

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

Вложения

Re: column not found !

От
Csaba Nagy
Дата:
For the error you get, I really can't think of anything else than the
field is really not there from the application side, and it's there on
the psql side.
This can happen if either of them started a transaction before creating
the table or adding that field, and didn't commit yet. In this case they
would see 2 different snapshots of the database, in one of them the
field exists, in the other doesn't... this is just a guess.

But why don't you use a prepared statement which gets all the fields,
and just display the requested ones ? Also see the previous threads
about directly setting input parameters from user input being dangerous.

Cheers,
Csaba.


On Thu, 2003-07-17 at 18:20, Savio Domnic wrote:
> Hello,
> I am trying to retrive a record from pqsl DB using the
> following steps.
>
> First I prepare a String Buffer "prepareSql".
>
> prepareSql.append("Select");
>
>     if(req.getParameter("firstname") != null){
>         prepareSql.append(" name,");
>     }
>     if(req.getParameter("city") != null){
>         prepareSql.append(" city,");
>     }
>     if(req.getParameter("zip") != null){
>         prepareSql.append(" zip,");
>     }
>     if(req.getParameter("country") != null){
>         prepareSql.append(" country,");
>     }
>     if(req.getParameter("email") != null){
>         prepareSql.append(" email,");
>     }
>     // Deleting the Coma at the end of an entity.
>     int sbLength = prepareSql.length();
>     prepareSql.deleteCharAt(sbLength - 1);
>
>     prepareSql.append(" from Personal where immat = " +
> Integer.parseInt(req.getParameter("immat")));
> return prepareSql.toString();
>
> Second I pass this string to a method thru a variable
> "sql" and execute this statement.
>
> stmt.executeQuery(sql);
>
> To my information I did a System.out.println(sql);
> and I got the result "Select name, zip, email from
> Personal where immat = 500103"
>
> I get the error "The column name immat not found." as
> the SQL Execption.
>
> I executed the same statement in the psql command line
> it was executing it and displaying the record.
>
> Can someone explain me what wrong I had made. I had
> also attached the codes for your reference.
>
> Thanks in advance.
> Domnic
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> ----
>

>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html