I think that I've found a little bug in the 7.1beta1 JDBC drivers. Attached is a simple test case which produces the problem on my setup (LinuxPPC 2000, on Apple PowerMac G3-400Mhz, 512MB). It would seem that the drivers and/or the DBMS has a problem with nested queries, even simple ones. Here's the stacktrace: Bad Long at org.postgresql.jdbc2.ResultSet.getLong(ResultSet.java:284) at Test.go(Test.java:35) at Test.main(Test.java:15) I'm using the 7.0.2 JDBC drivers against the 7.1beta1 backend and everything seems to be working fine. Stu. -- Stu Coates Chelmsford, England U.K. http://www.StuCoates.com/ The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners.
import java.sql.*; import java.io.*; public class Test { public static void main(String [] args) { if(args.length!=3) { System.err.println("Usage: <URL> <UID> <PWD>"); System.exit(1); } Test app=new Test(); try { app.go(args[0],args[1],args[2]); } catch(Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } } private void go(String url,String uid,String pwd) throws Exception { Class.forName("org.postgresql.Driver"); Connection connection=DriverManager.getConnection(url,uid,pwd); connection.setAutoCommit(false); PreparedStatement s=connection.prepareStatement("select mykey from mytest"); ResultSet rs=s.executeQuery(); while(rs.next()) { PreparedStatement s2=connection.prepareStatement("select * from mytest where mykey=?"); s2.setLong(1,rs.getLong(1)); ResultSet rs2=s2.executeQuery(); while(rs2.next()) { System.out.println(rs2.getLong(1) + " " + rs2.getString(2)); } rs2.close(); s.close(); } rs.close(); s.close(); connection.commit(); connection.close(); } }
drop table mytest; create table mytest (mykey int8, foo varchar(20)); insert into mytest(mykey,foo) values (0,'stuff'); insert into mytest(mykey,foo) values (1,'stuff'); insert into mytest(mykey,foo) values (2,'stuff'); insert into mytest(mykey,foo) values (3,'stuff'); insert into mytest(mykey,foo) values (4,'stuff'); insert into mytest(mykey,foo) values (5,'stuff'); insert into mytest(mykey,foo) values (6,'stuff'); insert into mytest(mykey,foo) values (7,'stuff'); insert into mytest(mykey,foo) values (8,'stuff'); insert into mytest(mykey,foo) values (9,'stuff');