Re: escape string for pgsql (using jdbc/java)?

Поиск
Список
Период
Сортировка
От Tobias Thierer
Тема Re: escape string for pgsql (using jdbc/java)?
Дата
Msg-id eplvti$2deb$1@news.hub.org
обсуждение исходный текст
Ответ на Re: escape string for pgsql (using jdbc/java)?  (Oliver Jowett <oliver@opencloud.com>)
Ответы Re: escape string for pgsql (using jdbc/java)?  (Dave Cramer <pg@fastcrypt.com>)
Список pgsql-jdbc
Oliver Jowett wrote:

> If you want something portable just use PreparedStatement.setString()
> and parameter placeholders. The "preparation" overhead you are worrying
> about is not really an issue as the PreparedStatement implementation is
> designed to handle one-shot queries as well as reused queries
> efficiently .. since PreparedStatement is often used just for parameter
> value interpolation to avoid exactly the issues you are encountering.

I'm not so worried about the performance. But if I have a column of type
SERIAL in my table, then I can retrieve the generated value using:

  statement.executeUpdate(sqlString, Statement.RETURN_GENERATED_KEYS);
  ResultSet resultSet = statement.getGeneratedKeys();
  Integer result;
  if (resultSet.next()) {
    result = resultSet.getInt(1);
  } else {
    result = null;
  }
  resultSet.close();

whereas it is not clear to me how this works with a prepared statement.
Strangely, PreparedStatement extends Statement, so PreparedStatement still
has the executeUpdate(String,int) method - but it is not clear to me whether
this method will throw the previously prepared statement away or what.

Is there any easy way to retrieve the generated value for the SERIAL column
when using a prepared statement?

   Tobias

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Oliver Jowett
Дата:
Сообщение: Re: escape string for pgsql (using jdbc/java)?
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: escape string for pgsql (using jdbc/java)?