{"record":{"id":"7650b29fca20a6d7","repo":"brettwooldridge/HikariCP","slug":"wrapped-statement-is-not-an-instance-of","errorCode":null,"errorMessage":"Wrapped statement is not an instance of {}","messagePattern":"Wrapped statement is not an instance of (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java","lineNumber":256,"sourceCode":"   @Override\n   public final boolean isWrapperFor(Class<?> iface) throws SQLException\n   {\n      return iface.isInstance(delegate) || (delegate != null && delegate.isWrapperFor(iface));\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   @SuppressWarnings(\"unchecked\")\n   public final <T> T unwrap(Class<T> iface) throws SQLException\n   {\n      if (iface.isInstance(delegate)) {\n         return (T) delegate;\n      }\n      else if (delegate != null) {\n          return delegate.unwrap(iface);\n      }\n\n      throw new SQLException(\"Wrapped statement is not an instance of \" + iface);\n   }\n}\n","sourceCodeStart":238,"sourceCodeEnd":259,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/pool/ProxyStatement.java#L238-L259","documentation":"ProxyStatement.unwrap(iface) throws SQLException unless the delegate Statement implements the requested interface or can itself unwrap to it. HikariCP proxies statements created on pooled connections, delegating unwrap to the driver's real statement.","triggerScenarios":"stmt.unwrap(OraclePreparedStatement.class)/PGStatement etc. when the underlying driver does not support it; unwrap with an interface unrelated to statements; prepared vs callable statement type mismatch.","commonSituations":"Setting vendor fetch/row prefetch hints, using vendor batching APIs, mocking statements in tests.","solutions":["Use stmt.isWrapperFor(iface) as a guard before unwrap","Unwrap to the exact vendor interface the driver documents (e.g. org.postgresql.PGStatement for getPrepareThreshold)","Set vendor hints via connection/statement properties or SQL hints instead where possible"],"exampleFix":"// before\n((OraclePreparedStatement) stmt.unwrap(OraclePreparedStatement.class)).setRowPrefetch(100);\n\n// after\nif (stmt.isWrapperFor(oracle.jdbc.OraclePreparedStatement.class)) {\n   stmt.unwrap(oracle.jdbc.OraclePreparedStatement.class).setRowPrefetch(100);\n}","handlingStrategy":"type-guard","validationCode":"if (stmt.isWrapperFor(VendorStatement.class)) { ... }","typeGuard":"boolean canUnwrapStmt(Statement s, Class<?> iface) {\n    try { return !s.isClosed() && s.isWrapperFor(iface); }\n    catch (SQLException e) { return false; }\n}","tryCatchPattern":"try { v = stmt.unwrap(iface); }\ncatch (SQLException e) {\n    if (e.getMessage().contains(\"not an instance of\")) { /* set hints via properties instead */ }\n    else throw e;\n}","preventionTips":["Guard unwrap with isWrapperFor","Use vendor connection properties for prefetch/hints when possible","Unwrap to the exact documented vendor statement interface"],"tags":["hikaricp","jdbc","unwrap","statement"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}