pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedException while doing ResultSetMetadata.getColumnName() after select setval()
3+ messages / 2 participants
[nested] [flat]
* Exception while doing ResultSetMetadata.getColumnName() after select setval()
@ 2007-09-17 22:30 Stephane Bailliez <sbailliez@gmail.com>
2007-09-18 00:10 ` Re: Exception while doing ResultSetMetadata.getColumnName() after select setval() Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 3+ messages in thread
From: Stephane Bailliez @ 2007-09-17 22:30 UTC (permalink / raw)
To: pgsql-jdbc
jdbc driver: postgresql-8.1-410.jdbc3.jar
Sun jdk 1.6.0_01 windows xp
postgresql 8.1.5 on windows xp and postgresql 8.1.9 on ubuntu
Came across what looks like a bug in the driver when I wanted to realign
sequences.
Works fine when I inject everything from pgadmin, but I have a java code
that insert every statement one by one and the 'verification' done by
the code throws up an exception.
sql is typically:
create table mytable ( serial id ... );
insert table (id, ...) values (101, ...);
..
-- this lines blows up with exception
select setval ('mytable_id', max(id)) from mytable;
It works fine if I wrap the select around another select ie something
like this:
select 1 from (select setval ('mytable_id', max(id)) from mytable) as
workaround;
Stacktrace is:
org.postgresql.util.PSQLException: The column index is out of range: 0,
number of columns: 1. at
org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getField(AbstractJdbc2ResultSetMetaData.java:639)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getColumnLabel(AbstractJdbc2ResultSetMetaData.java:279)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getColumnName(AbstractJdbc2ResultSetMetaData.java:294)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:175)
at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:107)
The code in iBatis does (see XXX note for line 175 reference) :
[...]
Statement statement = conn.createStatement();
println(command);
boolean hasResults = false;
if (stopOnError) {
hasResults = statement.execute(command.toString());
} else {
try {
statement.execute(command.toString());
} catch (SQLException e) {
e.fillInStackTrace();
printlnError("Error executing: " + command);
printlnError(e);
}
}
if (autoCommit && !conn.getAutoCommit()) {
conn.commit();
}
ResultSet rs = statement.getResultSet();
if (hasResults && rs != null) {
ResultSetMetaData md = rs.getMetaData();
int cols = md.getColumnCount();
for (int i = 0; i < cols; i++) {
String name = md.getColumnName(i); // XXX Exception here
print(name + "\t");
}
println("");
while (rs.next()) {
for (int i = 0; i < cols; i++) {
String value = rs.getString(i);
print(value + "\t");
}
println("");
}
}
command = null;
try {
statement.close();
} catch (Exception e) {
// Ignore to workaround a bug in Jakarta DBCP
}
[...]
cheers,
-- stephane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Exception while doing ResultSetMetadata.getColumnName() after select setval()
2007-09-17 22:30 Exception while doing ResultSetMetadata.getColumnName() after select setval() Stephane Bailliez <sbailliez@gmail.com>
@ 2007-09-18 00:10 ` Kris Jurka <books@ejurka.com>
2007-09-18 11:03 ` Re: Exception while doing ResultSetMetadata.getColumnName() after select setval() Stephane Bailliez <sbailliez@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Kris Jurka @ 2007-09-18 00:10 UTC (permalink / raw)
To: Stephane Bailliez <sbailliez@gmail.com>; +Cc: pgsql-jdbc
On Tue, 18 Sep 2007, Stephane Bailliez wrote:
> jdbc driver: postgresql-8.1-410.jdbc3.jar
> Sun jdk 1.6.0_01 windows xp
> postgresql 8.1.5 on windows xp and postgresql 8.1.9 on ubuntu
>
>
> ResultSetMetaData md = rs.getMetaData();
> int cols = md.getColumnCount();
> for (int i = 0; i < cols; i++) {
> String name = md.getColumnName(i); // XXX Exception here
> print(name + "\t");
In JDBC columns go from 1 -> count, not 0 -> count-1.
Kris Jurka
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Exception while doing ResultSetMetadata.getColumnName() after select setval()
2007-09-17 22:30 Exception while doing ResultSetMetadata.getColumnName() after select setval() Stephane Bailliez <sbailliez@gmail.com>
2007-09-18 00:10 ` Re: Exception while doing ResultSetMetadata.getColumnName() after select setval() Kris Jurka <books@ejurka.com>
@ 2007-09-18 11:03 ` Stephane Bailliez <sbailliez@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Stephane Bailliez @ 2007-09-18 11:03 UTC (permalink / raw)
To: pgsql-jdbc
Kris Jurka wrote:
>
> In JDBC columns go from 1 -> count, not 0 -> count-1.
ah.. one more reason to get rid of this script I suppose. Thanks for the
heads up.
for the records, the previous workaround was of course not working..(I
put that on the lack of sleep) it needed to be wrapped into insert in a
temp table to avoid the result set issue.
cheers,
-- stephane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-09-18 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-09-17 22:30 Exception while doing ResultSetMetadata.getColumnName() after select setval() Stephane Bailliez <sbailliez@gmail.com>
2007-09-18 00:10 ` Kris Jurka <books@ejurka.com>
2007-09-18 11:03 ` Re: Exception while doing ResultSetMetadata.getColumnName() after select setval() Stephane Bailliez <sbailliez@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox