I'm working with a Postgres db in java with java.sql. Can't copy the whole snippet due to nda, but it looks like this:
private final PostgresConnection postgresConnection = PostgresConnection.getInstance();
preparedStatement = postgresConnection.getConnection().
prepareStatement("Insert into someTable(someColumn) values(?) RETURNING id");
preparedStatement.setString(i, (String) someParam);
resultSet = preparedStatement.executeQuery();
resultSet.next();
ResultSetMetaData meta = resultSet.getMetaData();
LOGGER.info("column count {}", meta.getColumnCount());
LOGGER.info("column type {}", meta.isAutoIncrement(0));
The query runs fine in the query tool (PgAdmin 4). It returns a single column, single row result. However, in java, the resultset refuses to give me anything. in the above code, the last line meta.isAutoIncrement(0)
, similar to resultSet.getInt(0)
gives the same error that does not make sense to me:
The column index is out of range: 0, number of columns: 1.
It's like the column array is secretly empty even though the resultSet is not aware of this.