Thread: error getString() --> decodeUTF8 / java.lang.ArrayIndexOutOfBoundsException: 5
error getString() --> decodeUTF8 / java.lang.ArrayIndexOutOfBoundsException: 5
From
Pedro Salazar
Date:
Greetings, I have function that returns a refcursor. When I call it in plpgsql shell, it returns all the rows correctly. But, When I call it in JDBC, when it tries to decode a string in specific row (7) it throws the following exception: java.lang.ArrayIndexOutOfBoundsException: 5 at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) at org.postgresql.core.Encoding.decode(Encoding.java:165) at org.postgresql.core.Encoding.decode(Encoding.java:181) at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) My refcursor returns the following list (the characters are in portuguese language): id | class ----+------------- 1 | Avenida 2 | Bairro 3 | Cais 4 | Estrada 5 | Largo 6 | Lugar 7 | Praça 8 | Rotunda 9 | Rua 10 | Sítio 11 | Travessa 12 | Urbanização The row number 7 (Praça) [character 'C' with cedilla] is throwing the above exception. How should I retrieve my string which has portuguese characters, in JDBC? thanks, Pedro Salazar. -- PS pedro-b-salazar@ptinovacao.pt PGP:0E129E31D803BC61
Hi, I forgot to tell that I'm using the JDBC driver build from postgresql 7.3.2. PS On Fri, 2003-04-11 at 11:19, Pedro Salazar wrote: > Greetings, > > I have function that returns a refcursor. When I call it in plpgsql > shell, it returns all the rows correctly. But, When I call it in JDBC, > when it tries to decode a string in specific row (7) it throws the > following exception: > > java.lang.ArrayIndexOutOfBoundsException: 5 > at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) > at org.postgresql.core.Encoding.decode(Encoding.java:165) > at org.postgresql.core.Encoding.decode(Encoding.java:181) > at > org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) > > My refcursor returns the following list (the characters are in > portuguese language): > > id | class > ----+------------- > 1 | Avenida > 2 | Bairro > 3 | Cais > 4 | Estrada > 5 | Largo > 6 | Lugar > 7 | Praça > 8 | Rotunda > 9 | Rua > 10 | Sítio > 11 | Travessa > 12 | Urbanização > > The row number 7 (Praça) [character 'C' with cedilla] is throwing the > above exception. How should I retrieve my string which has portuguese > characters, in JDBC? > > thanks, > Pedro Salazar. -- PS pedro-b-salazar@ptinovacao.pt PGP:0E129E31D803BC61
Pedro, If you were running the latest build from http://jdbc.postgresql.org you would see the following improved error message: Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database. thanks, --Barry Pedro Salazar wrote: > Hi, > > I forgot to tell that I'm using the JDBC driver build from postgresql > 7.3.2. > > PS > > On Fri, 2003-04-11 at 11:19, Pedro Salazar wrote: > >>Greetings, >> >>I have function that returns a refcursor. When I call it in plpgsql >>shell, it returns all the rows correctly. But, When I call it in JDBC, >>when it tries to decode a string in specific row (7) it throws the >>following exception: >> >>java.lang.ArrayIndexOutOfBoundsException: 5 >> at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) >> at org.postgresql.core.Encoding.decode(Encoding.java:165) >> at org.postgresql.core.Encoding.decode(Encoding.java:181) >> at >>org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) >> >>My refcursor returns the following list (the characters are in >>portuguese language): >> >> id | class >>----+------------- >> 1 | Avenida >> 2 | Bairro >> 3 | Cais >> 4 | Estrada >> 5 | Largo >> 6 | Lugar >> 7 | Praça >> 8 | Rotunda >> 9 | Rua >> 10 | Sítio >> 11 | Travessa >> 12 | Urbanização >> >>The row number 7 (Praça) [character 'C' with cedilla] is throwing the >>above exception. How should I retrieve my string which has portuguese >>characters, in JDBC? >> >>thanks, >>Pedro Salazar.
Barry, Besides the improved message issue, I tried with a database with the default locale (C), but I also tried to restore the database to the cluster with portuguese locale (pt_PT) (initdb --locale=pt_PT --lc-colate=pt_PT --lc-ctype=pt_PT --lc-message=pt_PT), and I still have the same error in JDBC (not the improved message, but the error). What configurations should I have to support portuguese locale in my database/JDBC? thanks, Pedro Salazar. On Fri, 2003-04-11 at 16:46, Barry Lind wrote: > Pedro, > > If you were running the latest build from http://jdbc.postgresql.org you > would see the following improved error message: > > Invalid character data was found. This is most likely caused by stored > data containing characters that are invalid for the character set the > database was created in. The most common example of this is storing > 8bit data in a SQL_ASCII database. > > thanks, > --Barry > > > Pedro Salazar wrote: > > Hi, > > > > I forgot to tell that I'm using the JDBC driver build from postgresql > > 7.3.2. > > > > PS > > > > On Fri, 2003-04-11 at 11:19, Pedro Salazar wrote: > > > >>Greetings, > >> > >>I have function that returns a refcursor. When I call it in plpgsql > >>shell, it returns all the rows correctly. But, When I call it in JDBC, > >>when it tries to decode a string in specific row (7) it throws the > >>following exception: > >> > >>java.lang.ArrayIndexOutOfBoundsException: 5 > >> at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) > >> at org.postgresql.core.Encoding.decode(Encoding.java:165) > >> at org.postgresql.core.Encoding.decode(Encoding.java:181) > >> at > >>org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) > >> > >>My refcursor returns the following list (the characters are in > >>portuguese language): > >> > >> id | class > >>----+------------- > >> 1 | Avenida > >> 2 | Bairro > >> 3 | Cais > >> 4 | Estrada > >> 5 | Largo > >> 6 | Lugar > >> 7 | Praça > >> 8 | Rotunda > >> 9 | Rua > >> 10 | Sítio > >> 11 | Travessa > >> 12 | Urbanização > >> > >>The row number 7 (Praça) [character 'C' with cedilla] is throwing the > >>above exception. How should I retrieve my string which has portuguese > >>characters, in JDBC? > >> > >>thanks, > >>Pedro Salazar. -- PS pedro-b-salazar@ptinovacao.pt PGP:0E129E31D803BC61
Attachment
I would like to know if there are any plans to implement the setCatalog function? I'm developing a swing based db admin tool that I think people will like. As my application works now the user has to manually create a new db item for each catalog. Get's a bit irritating after a while. Perhaps this is not a very important function for most people. If I find a solution can I get it included in the driver? Another question I have asked about earlier is about DatabaseMetaData.getExportedKey(). I got the answer that it only works if one of the columns in a constraint is a primary key. My problem is that I get an empty resultSet when asking for keys I know exist. Someone else beside me who thinks this is wrong, even though the jdbc spec might say otherwise? Regards, Patrik Lundgren
On Mon, 2003-04-14 at 07:14, Patrik Lundgren wrote: > I would like to know if there are any plans to implement the setCatalog > function? Not at the moment. Essentially you would internally have to drop the connection and recreate to another catalog(db). The driver cannot do this, as it is connection based. In fact psql doesn't do it either, it must drop and recreate the connection as wll > > I'm developing a swing based db admin tool that I think people will > like. As my application works now the user has to manually create a new > db item for each catalog. Get's a bit irritating after a while. > > Perhaps this is not a very important function for most people. If I find > a solution can I get it included in the driver? You can certainly send a patch in. > > Another question I have asked about earlier is about > DatabaseMetaData.getExportedKey(). I got the answer that it only works > if one of the columns in a constraint is a primary key. My problem is > that I get an empty resultSet when asking for keys I know exist. Someone > else beside me who thinks this is wrong, even though the jdbc spec might > say otherwise? Can you define how you expect this to work? What are you looking for; Foreign Keys that are related to non-primary keys in another table? Dave > > Regards, > Patrik Lundgren > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly -- Dave Cramer <Dave@micro-automation.net>
>> Another question I have asked about earlier is about >> DatabaseMetaData.getExportedKey(). I got the answer that it only works >> if one of the columns in a constraint is a primary key. My problem is >> that I get an empty resultSet when asking for keys I know exist. >> Someone else beside me who thinks this is wrong, even though the jdbc >> spec might say otherwise? >Can you define how you expect this to work? What are you looking for; Foreign Keys that are related to non-primary keys in another table? Well since a can create a foreign key that is related to a non-primary key in another table it only seems natural that I should be able to find out if it's there also...? The only demand from postgres seems to be that the column in the other table is unique, not a primary key also. jxDBCon returns the foreign keys, pgAdminII does also... By the way, jxDBCon has a working setCatalog. Don't ask me how it's done, but it works. It does have some other big problems though that makes it nearly unusable for my cause, like getting 4096 as the length of all arrays. In MSSQL for example I don't think you can create a foreign key if one of the columns isn't a primary key, but in postgres I know it's possible, therefore I think they should be able to be gotten as well, please correct me if I'm wrong. /Patrik
AFAIK, the problem is the encoding, not the locale. Did you try initdb -E latin1 ??? []'s Daniel Serodio On Mon, 2003-04-14 at 07:09, Pedro Salazar wrote: > Barry, > > Besides the improved message issue, I tried with a database with the > default locale (C), but I also tried to restore the database to the > cluster with portuguese locale (pt_PT) (initdb --locale=pt_PT > --lc-colate=pt_PT --lc-ctype=pt_PT --lc-message=pt_PT), and I still have > the same error in JDBC (not the improved message, but the error). > > What configurations should I have to support portuguese locale in my > database/JDBC? > > thanks, > Pedro Salazar. > > On Fri, 2003-04-11 at 16:46, Barry Lind wrote: > > Pedro, > > > > If you were running the latest build from http://jdbc.postgresql.org you > > would see the following improved error message: > > > > Invalid character data was found. This is most likely caused by stored > > data containing characters that are invalid for the character set the > > database was created in. The most common example of this is storing > > 8bit data in a SQL_ASCII database. > > > > thanks, > > --Barry > > > > > > Pedro Salazar wrote: > > > Hi, > > > > > > I forgot to tell that I'm using the JDBC driver build from postgresql > > > 7.3.2. > > > > > > PS > > > > > > On Fri, 2003-04-11 at 11:19, Pedro Salazar wrote: > > > > > >>Greetings, > > >> > > >>I have function that returns a refcursor. When I call it in plpgsql > > >>shell, it returns all the rows correctly. But, When I call it in JDBC, > > >>when it tries to decode a string in specific row (7) it throws the > > >>following exception: > > >> > > >>java.lang.ArrayIndexOutOfBoundsException: 5 > > >> at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) > > >> at org.postgresql.core.Encoding.decode(Encoding.java:165) > > >> at org.postgresql.core.Encoding.decode(Encoding.java:181) > > >> at > > >>org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) > > >> > > >>My refcursor returns the following list (the characters are in > > >>portuguese language): > > >> > > >> id | class > > >>----+------------- > > >> 1 | Avenida > > >> 2 | Bairro > > >> 3 | Cais > > >> 4 | Estrada > > >> 5 | Largo > > >> 6 | Lugar > > >> 7 | Praça > > >> 8 | Rotunda > > >> 9 | Rua > > >> 10 | Sítio > > >> 11 | Travessa > > >> 12 | Urbanização > > >> > > >>The row number 7 (Praça) [character 'C' with cedilla] is throwing the > > >>above exception. How should I retrieve my string which has portuguese > > >>characters, in JDBC? > > >> > > >>thanks, > > >>Pedro Salazar. -- Daniel Serodio CheckForte 5582-6016
Patrick, Ok, I don't have a problem putting in the foreign key stuff, as it is above and beyond the spec, and also something postgres supports. Kris Jurka did most of the work on the imported/exported keys, he may have an opinion as well? As far as the setCatalog goes, this is probably OK too, if you get it working, I would support it. Dave On Mon, 2003-04-14 at 08:04, Patrik Lundgren wrote: > >> Another question I have asked about earlier is about > >> DatabaseMetaData.getExportedKey(). I got the answer that it only > works > >> if one of the columns in a constraint is a primary key. My problem is > > >> that I get an empty resultSet when asking for keys I know exist. > >> Someone else beside me who thinks this is wrong, even though the jdbc > > >> spec might say otherwise? > > >Can you define how you expect this to work? What are you looking for; > Foreign Keys that are related to non-primary keys in another table? > > Well since a can create a foreign key that is related to a non-primary > key in another table it only seems natural that I should be able to find > out if it's there also...? The only demand from postgres seems to be > that the column in the other table is unique, not a primary key also. > > jxDBCon returns the foreign keys, pgAdminII does also... By the way, > jxDBCon has a working setCatalog. Don't ask me how it's done, but it > works. It does have some other big problems though that makes it nearly > unusable for my cause, like getting 4096 as the length of all arrays. > > In MSSQL for example I don't think you can create a foreign key if one > of the columns isn't a primary key, but in postgres I know it's > possible, therefore I think they should be able to be gotten as well, > please correct me if I'm wrong. > > /Patrik > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html -- Dave Cramer <Dave@micro-automation.net>
Pedro, I was talking about database character set, not locale. If you connect to psql and issue the \l command you will see a listing of databases with their character sets. thanks, --Barry Pedro Salazar wrote: > Barry, > > Besides the improved message issue, I tried with a database with the > default locale (C), but I also tried to restore the database to the > cluster with portuguese locale (pt_PT) (initdb --locale=pt_PT > --lc-colate=pt_PT --lc-ctype=pt_PT --lc-message=pt_PT), and I still have > the same error in JDBC (not the improved message, but the error). > > What configurations should I have to support portuguese locale in my > database/JDBC? > > thanks, > Pedro Salazar. > > On Fri, 2003-04-11 at 16:46, Barry Lind wrote: > >>Pedro, >> >>If you were running the latest build from http://jdbc.postgresql.org you >>would see the following improved error message: >> >>Invalid character data was found. This is most likely caused by stored >>data containing characters that are invalid for the character set the >>database was created in. The most common example of this is storing >>8bit data in a SQL_ASCII database. >> >>thanks, >>--Barry >> >> >>Pedro Salazar wrote: >> >>>Hi, >>> >>>I forgot to tell that I'm using the JDBC driver build from postgresql >>>7.3.2. >>> >>>PS >>> >>>On Fri, 2003-04-11 at 11:19, Pedro Salazar wrote: >>> >>> >>>>Greetings, >>>> >>>>I have function that returns a refcursor. When I call it in plpgsql >>>>shell, it returns all the rows correctly. But, When I call it in JDBC, >>>>when it tries to decode a string in specific row (7) it throws the >>>>following exception: >>>> >>>>java.lang.ArrayIndexOutOfBoundsException: 5 >>>> at org.postgresql.core.Encoding.decodeUTF8(Encoding.java:254) >>>> at org.postgresql.core.Encoding.decode(Encoding.java:165) >>>> at org.postgresql.core.Encoding.decode(Encoding.java:181) >>>> at >>>>org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet.java:97) >>>> >>>>My refcursor returns the following list (the characters are in >>>>portuguese language): >>>> >>>>id | class >>>>----+------------- >>>> 1 | Avenida >>>> 2 | Bairro >>>> 3 | Cais >>>> 4 | Estrada >>>> 5 | Largo >>>> 6 | Lugar >>>> 7 | Praça >>>> 8 | Rotunda >>>> 9 | Rua >>>>10 | Sítio >>>>11 | Travessa >>>>12 | Urbanização >>>> >>>>The row number 7 (Praça) [character 'C' with cedilla] is throwing the >>>>above exception. How should I retrieve my string which has portuguese >>>>characters, in JDBC? >>>> >>>>thanks, >>>>Pedro Salazar.
On 14 Apr 2003, Dave Cramer wrote: [ foreign keys don't show up if they reference a unique key other than the primary key] Basically the problem is that there is no real link between the foreign key and the index. With a primary key this is not a problem because there can be only one primary key per table. Supposing I had done: create table tab (a int not null, b int not null); create unique index t1 on tab (a,b); create unique index t2 on tab (a,b); create unique index t3 on tab (b,a); create table tab2 (a int, b int); alter table tab2 add constraint tab2_fk_tab foreign key (a,b) references tab(a,b); What is the resulting value in the PK_NAME column from a getCrossReference call? Actually looking at the javadoc it appears this may be null which would be OK. Getting at the data could be another problem as it is rather complicated for the existing functionality. Unfortunately jxdbcon is LGPL licensed which is no good as a source of inspiration to our BSD driver. I will be away for the next two weeks and will look at this more closely later. My initial reaction is that this will depend on Joe Conway's work on the new array functionality and getting something like contrib/array integrated into the backend, which will then allow this for >= 7.4 servers. Kris Jurka
Well, if pgAdminII does it then we can use it for inspiration. Dave On Wed, 2003-04-16 at 03:55, Kris Jurka wrote: > On 14 Apr 2003, Dave Cramer wrote: > > [ foreign keys don't show up if they reference a unique key other than the > primary key] > > Basically the problem is that there is no real link between the foreign > key and the index. With a primary key this is not a problem because there > can be only one primary key per table. Supposing I had done: > > create table tab (a int not null, b int not null); > > create unique index t1 on tab (a,b); > create unique index t2 on tab (a,b); > create unique index t3 on tab (b,a); > > create table tab2 (a int, b int); > alter table tab2 add constraint tab2_fk_tab foreign key (a,b) references > tab(a,b); > > What is the resulting value in the PK_NAME column from a getCrossReference > call? > > Actually looking at the javadoc it appears this may be null which would be > OK. Getting at the data could be another problem as it is rather > complicated for the existing functionality. > > Unfortunately jxdbcon is LGPL licensed which is no good as a source of > inspiration to our BSD driver. I will be away for the next two weeks and > will look at this more closely later. My initial reaction is that this > will depend on Joe Conway's work on the new array functionality and > getting something like contrib/array integrated into the backend, which > will then allow this for >= 7.4 servers. > > Kris Jurka > > -- Dave Cramer <Dave@micro-automation.net>