PSQLException: The column index is out of range: 1, number of columns: 0

I tried to write a insert statement with Spring JDB Template for an PostgreSQL Database. My insert string looked like this:

final String sql = "INSERT INTO products (prod_name, prod_key, artifact_id, group_id, link, src, prod_type) VALUES ('?','?','?','?','?','?','?')";

And I got this Exception:

PreparedStatementCallback; SQL []; The column index is out of range: 1, number of columns: 0.; nested exception is org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.

The Problem was that I used ” ‘ ” inside of the sql string close to the “?”. After I removed the ” ‘ ” strings it worked perfectly.

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

4 thoughts on “PSQLException: The column index is out of range: 1, number of columns: 0

  1. I’m having the same error but without using “‘” just like this:

    …WHERE “).
    append(” C007.C007_CODIGO_EVENTO > ? “).
    append(” ORDER BY C007.C007_CODIGO_EVENTO “).
    append(” LIMIT 1000 “);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: