pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedJVM & JDBC Upgrade --- Help !!
6+ messages / 4 participants
[nested] [flat]
* JVM & JDBC Upgrade --- Help !!
@ 2011-09-21 22:53 Craig Golby <craig.golby@dignitas.ltd.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Craig Golby @ 2011-09-21 22:53 UTC (permalink / raw)
To: pgsql-jdbc
We have a software application (http://www.credability.info) running quite
happily on Tomcat 5.5, Java 1.5 and PostgreSQL 8.2.6, using the pg73jdbc3
drivers.
Having recently upgraded to Java to 1.6 with no issues, we have now decided
to upgrade to Tomcat to v7, but have struggled to get it to work, with
issues around SSL & Db Connectivity. To try and resolve one thing at a
time, I have been trying to get my Tomcat 5.5 installation working with the
new Drivers so either postgresql-9.1-901.jdbc3, or postgresql-9.1-901.jdbc4.
And here it gets a bit strange. Without wanting to state the obvious, the
code used is standardised, and the application loads modules of information
to load onto the screen. When you log onto the secure area, it is obviously
making a Db connection to validate your user, and the first couple of screen
modules appear. However it then stops, and in the log files it returns the
error ..
java.lang.ArrayIndexOutOfBoundsException: 0
against a particular Bean.
I have compared the working code with what appears to be the broken one, and
the key difference is that the first few are simple queries returning single
values, whereas this one returns a range of variables and records and we use
the ResultSetMetaData characteristics to define the necessary Array to store
the result on the fly
Code Snippet .
if(conn != null)
{ try
{ pStmt = conn.prepareStatement(stmtStringSel);
pStmt.clearParameters();
rsID = pStmt.executeQuery();
//Set up the Array
ResultSetMetaData rsmd = rsID.getMetaData();
int columnCount = rsmd.getColumnCount();
int rowCount = 7;
rsOpened = new String[rowCount][columnCount];
int r=0;
while(rsID.next())
{ int c=0;
int rsc=1;
while (rsc <= columnCount)
{ rsOpened[r][c] = rsID.getString(rsc);
c++;
rsc++;
}
r++;
}
pStmt.close();
}catch(SQLException se) {se.printStackTrace();}
}
Should this still work, and can you suggest anything that might help me
narrow down my problem.
When I swap my pg73jdbc3 drivers back into place it all works fine.
Cheers
Craig
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JVM & JDBC Upgrade --- Help !!
@ 2011-09-22 04:25 Craig Ringer <ringerc@ringerc.id.au>
2011-09-22 14:57 ` Re: JVM & JDBC Upgrade --- Help !! dmp <danap@ttc-cmc.net>
2011-09-22 23:16 ` Re: JVM & JDBC Upgrade --- Help !! Craig Golby <craig.golby@dignitas.ltd.uk>
2011-09-22 23:42 ` Re: JVM & JDBC Upgrade --- Help !! Oliver Jowett <oliver@opencloud.com>
0 siblings, 3 replies; 6+ messages in thread
From: Craig Ringer @ 2011-09-22 04:25 UTC (permalink / raw)
To: pgsql-jdbc
On 09/22/2011 06:53 AM, Craig Golby wrote:
>
> Code Snippet ...
>
> if(conn != null)
>
> { try
>
> { pStmt = conn.prepareStatement(stmtStringSel);
>
> pStmt.clearParameters();
>
> rsID = pStmt.executeQuery();
>
> //Set up the Array
>
> ResultSetMetaData rsmd = rsID.getMetaData();
>
> int columnCount = rsmd.getColumnCount();
>
> int rowCount = 7;
>
> rsOpened = new String[rowCount][columnCount];
>
> int r=0;
>
> while(rsID.next())
>
> { int c=0;
>
> int rsc=1;
>
> while (rsc <= columnCount)
>
> { rsOpened[r][c] = rsID.getString(rsc);
>
Is the above line where the exception is thrown from? You didn't provide
full exception context.
If so, check and make sure the column count reported by `getColumnCount'
matches what you expect and what the old driver provided. Compare it to
the table. Compare the column-list metadata output from the old and new
drivers to see which column(s) have appeared/disappeared.
--
Craig Ringer
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JVM & JDBC Upgrade --- Help !!
2011-09-22 04:25 Re: JVM & JDBC Upgrade --- Help !! Craig Ringer <ringerc@ringerc.id.au>
@ 2011-09-22 14:57 ` dmp <danap@ttc-cmc.net>
2 siblings, 0 replies; 6+ messages in thread
From: dmp @ 2011-09-22 14:57 UTC (permalink / raw)
To: pgsql-jdbc
On 09/22/2011 06:53 AM, Craig Golby wrote:
>>
>> Code Snippet …
>>
>> if(conn != null)
>>
>> { try
>>
>> { pStmt = conn.prepareStatement(stmtStringSel);
>>
>> pStmt.clearParameters();
>>
>> rsID = pStmt.executeQuery();
>>
>> //Set up the Array
>>
>> ResultSetMetaData rsmd = rsID.getMetaData();
>>
>> int columnCount = rsmd.getColumnCount();
>>
>> int rowCount = 7;
>>
>> rsOpened = new String[rowCount][columnCount];
>>
>> int r=0;
>>
>> while(rsID.next())
>>
>> { int c=0;
>>
>> int rsc=1;
>>
>> while (rsc <= columnCount)
>>
>> { rsOpened[r][c] = rsID.getString(rsc);
>>
Craig Ringer wrote:
> Is the above line where the exception is thrown from? You didn't provide
> full exception context.
>
> If so, check and make sure the column count reported by `getColumnCount'
> matches what you expect and what the old driver provided. Compare it to
> the table. Compare the column-list metadata output from the old and new
> drivers to see which column(s) have appeared/disappeared.
>
> --
> Craig Ringer
I don't think this coming from the JDBC, your code is throwing the error,
java.lang.ArrayIndexOutOfBoundsException. That rowCount assignment looks
suspicious. The columnCount is coming directly from getColumnCount() so
I don't thinks its the culprit. Put a a system.out in there for r & c to
track.
danap.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JVM & JDBC Upgrade --- Help !!
2011-09-22 04:25 Re: JVM & JDBC Upgrade --- Help !! Craig Ringer <ringerc@ringerc.id.au>
@ 2011-09-22 23:16 ` Craig Golby <craig.golby@dignitas.ltd.uk>
2 siblings, 0 replies; 6+ messages in thread
From: Craig Golby @ 2011-09-22 23:16 UTC (permalink / raw)
To: pgsql-jdbc
Craig, danap, thanks for the steer. I guess what is confusing me is that it
works for pg73jdbc3 and fails when I switch it for postgresql-8.3-603.jdbc4
I have added a load of Sys Outs to try and figure out the location of the
error, the code is pasted below.
When I run this on the pg73jdbc3 Driver, so the existing solution, I get ..
credability:Bean:reports:ataglance - starting getCurrent : columnCount = 5
credability:Bean:reports:ataglance - starting getCurrent : rowCount = 3
and of course there are multiple loops of the sysouts in the While loops.
However when I run it using the postgresql-8.3-603.jdbc4, it spools out the
following and then stops working.
credability:Bean:reports:ataglance - starting getCurrent : columnCount = 5
credability:Bean:reports:ataglance - starting getCurrent : rowCount = 0
credability:Bean:reports:ataglance - starting getCurrent : b4 while
credability:Bean:reports:ataglance - starting getCurrent : in while
credability:Bean:reports:ataglance - starting getCurrent : in 2nd while
credability:Bean:reports:ataglance - starting getCurrent : r = 0
credability:Bean:reports:ataglance - starting getCurrent : c = 0
So either the query is returning no data or the getFetchSize isnt working
properly.
Thoughts ??
CODE SNIPPET .
if(conn != null)
{ try
{ pStmt = conn.prepareStatement(stmtStringSel);
pStmt.clearParameters();
rsID = pStmt.executeQuery();
//Set up the Array
ResultSetMetaData rsmd = rsID.getMetaData();
int columnCount = rsmd.getColumnCount();
int rowCount = rsID.getFetchSize();
rsCurrentreturn = new String[rowCount][columnCount];
System.out.println(sysOut + "starting getCurrent : columnCount = " +
columnCount);
System.out.println(sysOut + "starting getCurrent : rowCount = " +
rowCount);
int r=0;
System.out.println(sysOut + "starting getCurrent : b4 while");
while(rsID.next())
{ System.out.println(sysOut + "starting getCurrent : in while");
int c=0;
int rsc=1;
while (rsc <= columnCount)
{ System.out.println(sysOut + "starting getCurrent : in 2nd
while");
System.out.println(sysOut + "starting getCurrent : r = " + r);
System.out.println(sysOut + "starting getCurrent : c = " + c);
rsCurrentreturn[r][c] = rsID.getString(rsc);
c++;
rsc++;
}
System.out.println(sysOut + "starting getCurrent : r++");
r++;
}
System.out.println(sysOut + "starting getCurrent : pStmt CLose");
pStmt.close();
}catch(SQLException se) {se.printStackTrace();}
System.out.println(sysOut + "starting getCurrent : Done");
}
stmtStringSel = "";
closeConnection();
System.out.println(sysOut + "starting getCurrent : Connection closed");
}
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Craig Ringer
Sent: 22 September 2011 05:26
To: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] JVM & JDBC Upgrade --- Help !!
On 09/22/2011 06:53 AM, Craig Golby wrote:
Code Snippet .
if(conn != null)
{ try
{ pStmt = conn.prepareStatement(stmtStringSel);
pStmt.clearParameters();
rsID = pStmt.executeQuery();
//Set up the Array
ResultSetMetaData rsmd = rsID.getMetaData();
int columnCount = rsmd.getColumnCount();
int rowCount = 7;
rsOpened = new String[rowCount][columnCount];
int r=0;
while(rsID.next())
{ int c=0;
int rsc=1;
while (rsc <= columnCount)
{ rsOpened[r][c] = rsID.getString(rsc);
Is the above line where the exception is thrown from? You didn't provide
full exception context.
If so, check and make sure the column count reported by `getColumnCount'
matches what you expect and what the old driver provided. Compare it to the
table. Compare the column-list metadata output from the old and new drivers
to see which column(s) have appeared/disappeared.
--
Craig Ringer
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JVM & JDBC Upgrade --- Help !!
2011-09-22 04:25 Re: JVM & JDBC Upgrade --- Help !! Craig Ringer <ringerc@ringerc.id.au>
@ 2011-09-22 23:42 ` Oliver Jowett <oliver@opencloud.com>
2011-09-25 23:16 ` Re: JVM & JDBC Upgrade --- Help !! Craig Golby <craig.golby@dignitas.ltd.uk>
2 siblings, 1 reply; 6+ messages in thread
From: Oliver Jowett @ 2011-09-22 23:42 UTC (permalink / raw)
To: craig.golby@dignitas.ltd.uk; +Cc: pgsql-jdbc
On 23 September 2011 11:16, Craig Golby <craig.golby@dignitas.ltd.uk> wrote:
> int rowCount = rsID.getFetchSize();
Well, there's your problem, getFetchSize() doesn't return the number
of rows in a resultset, it returns whatever fetch size is in use,
which defaults to 0.
(That's probably something that has changed since the 7.3 driver - the
7.3 driver did do some odd nonstandard things in that area, and if you
relied on them then yes your code will break)
Oliver
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: JVM & JDBC Upgrade --- Help !!
2011-09-22 04:25 Re: JVM & JDBC Upgrade --- Help !! Craig Ringer <ringerc@ringerc.id.au>
2011-09-22 23:42 ` Re: JVM & JDBC Upgrade --- Help !! Oliver Jowett <oliver@opencloud.com>
@ 2011-09-25 23:16 ` Craig Golby <craig.golby@dignitas.ltd.uk>
0 siblings, 0 replies; 6+ messages in thread
From: Craig Golby @ 2011-09-25 23:16 UTC (permalink / raw)
To: 'Oliver Jowett' <oliver@opencloud.com>; +Cc: pgsql-jdbc
Hi Oliver, a little research later and it does appear to be the case that
getFetchSize used to return the size of the resultset, but now doesn’t.
We were looking to upgrade Apache, Tomcat, PostgreSQL DRivers and ultimately
PostgreSQL itself, but in all honesty to change all the instances of this to
work in some other way would be a major undertaking for the application
developers.
As such, we will likely continue with what we have, as simply put, it works
!!
Thanks for your input.
Craig
-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Oliver Jowett
Sent: 23 September 2011 00:42
To: craig.golby@dignitas.ltd.uk
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] JVM & JDBC Upgrade --- Help !!
On 23 September 2011 11:16, Craig Golby <craig.golby@dignitas.ltd.uk> wrote:
> int rowCount = rsID.getFetchSize();
Well, there's your problem, getFetchSize() doesn't return the number
of rows in a resultset, it returns whatever fetch size is in use,
which defaults to 0.
(That's probably something that has changed since the 7.3 driver - the
7.3 driver did do some odd nonstandard things in that area, and if you
relied on them then yes your code will break)
Oliver
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2011-09-25 23:16 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-21 22:53 JVM & JDBC Upgrade --- Help !! Craig Golby <craig.golby@dignitas.ltd.uk>
2011-09-22 04:25 Re: JVM & JDBC Upgrade --- Help !! Craig Ringer <ringerc@ringerc.id.au>
2011-09-22 14:57 ` dmp <danap@ttc-cmc.net>
2011-09-22 23:16 ` Craig Golby <craig.golby@dignitas.ltd.uk>
2011-09-22 23:42 ` Oliver Jowett <oliver@opencloud.com>
2011-09-25 23:16 ` Craig Golby <craig.golby@dignitas.ltd.uk>
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