Re: ClassCastException DelegatingPreparedStatement

Поиск
Список
Период
Сортировка
От Kris Jurka
Тема Re: ClassCastException DelegatingPreparedStatement
Дата
Msg-id Pine.BSO.4.64.0701041231420.24201@leary2.csoft.net
обсуждение исходный текст
Ответ на ClassCastException DelegatingPreparedStatement  (Kevin Murphy <murphy@genome.chop.edu>)
Список pgsql-jdbc

On Tue, 2 Jan 2007, Kevin Murphy wrote:

> I'm just getting around to testing out the advice I got from this list a
> couple weeks ago about prepare thresholds (thanks, Mark & Dave).
>
> Using code modeled after the PG JDBC "Server Prepared Statements" code
> example, I'm getting this runtime error:
>
> java.lang.ClassCastException:
> org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement
>
> on the line marked with an asterisk:
>
>           try {
>               Class.forName("org.postgresql.Driver");
>           } catch(Exception e) {
>               printError("org.postgresql.Driver class not found in
> getMedlineListFromParsedText(): ", e.getMessage());
>           }
>           prestmt = conn.prepareStatement(query);
> *        org.postgresql.PGStatement pgstmt =
> (org.postgresql.PGStatement)prestmt;
>           pgstmt.setPrepareThreshold(0);
>
> I'm using DBCP pooled connections within tomcat.  Versions: PG 8.1,
> postgresql-8.1-407.jdbc3.jar, tomcat 5.5.20, Java 1.5
>

DBCP is wrapping the postgresql statement so you need to unwrap it using
something like:

Statement unwrapped =
((DelegatingPreparedStatement)prestmt).getInnermostDelegate();

org.postgresql.PGStatement pgstmt = (org.postgresql.PGStatement)unwrapped;

Kris Jurka

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

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: Support for DatabaseMetadata: getCatalogName, getTableName,
Следующее
От: Kris Jurka
Дата:
Сообщение: Re: Driver Bug