Обсуждение: Problem with string parameters

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

Problem with string parameters

От
"RichT"
Дата:
Can anyone help with this?

I am using Postgres 7.4.13 JDBC interface and I get
"PSQLException: Parameter index out of range."

The query is:
INSERT INTO shm_log_sources
SELECT ? as name, ci.source_id, true as active, true as monitor,
    0 as alerts_sent, '' as comment
FROM shm_current_ids ci LEFT OUTER JOIN shm_log_sources ls
    ON ci.source_id = ls.source_id AND ls.name = ?
WHERE ls.active IS NULL

The code does
pStmt = conn.prepareStatement(query);
pStmt.clearParameters();
...
int paramNo = 1;
pStmt.setString(paramNo, monitorName);
...
paramNo++;
pStmt.setString(paramNo, monitorName);

Where monitorName is the String "SourceHealth"

Why do I get the exception?


Re: Problem with string parameters

От
Giuseppe Sacco
Дата:
Il giorno sab, 24/03/2007 alle 12.35 -0700, RichT ha scritto:
> Can anyone help with this?
>
> I am using Postgres 7.4.13 JDBC interface and I get
> "PSQLException: Parameter index out of range."
>
> The query is:
> INSERT INTO shm_log_sources
> SELECT ? as name, ci.source_id, true as active, true as monitor,
>     0 as alerts_sent, '' as comment
> FROM shm_current_ids ci LEFT OUTER JOIN shm_log_sources ls
>     ON ci.source_id = ls.source_id AND ls.name = ?
> WHERE ls.active IS NULL
[...]

I think you may only bind variable in the WHERE clause. You cannot bud
variable in the SELECT part.

Bye,
Giuseppe