bumpert
asked on
Invalid character data was found
Hi, i'm trying to select data from my postgresql database with a java application that use the lastest jdbc drivers from postgre developper. I have frenc character into some text column and when i tried to retrieve it (my ResultSet . getString("columnName")) i got this error "Invalid character data was found".
I think there something to do with the charset but i tried to put it at UTF-8 or CP1252 without result....
someone can help... i'm stuck here in my project and couldn't make anything else before fixing this problem
thx
I think there something to do with the charset but i tried to put it at UTF-8 or CP1252 without result....
someone can help... i'm stuck here in my project and couldn't make anything else before fixing this problem
thx
check if the version of JDBC you use support the charset you are using on the DB.
What version of java are you using ?
ASKER
i didn't find anything about the which charset is supported or not by this jdbc...
i use java 1.4.2_05
thx
i use java 1.4.2_05
thx
Try passing the charset in the connection string. e.g.
jdbc:postgresql://localhos t:5432/tes tdb?charSe t=LATIN1
jdbc:postgresql://localhos
ASKER
i tried passing the charset in the connection string and tried to pass it by the Properties parameter without result
Please post exact stack trace
>>i tried to put it at UTF-8
That should be
jdbc:postgresql://localhos t:5432/tes tdb?charSe t=UNICODE
Make sure you haven't got data in there that's invalid (it may be nothing to do with accented characters)
That should be
jdbc:postgresql://localhos
Make sure you haven't got data in there that's invalid (it may be nothing to do with accented characters)
ASKER
i tried with unicode without success...
i know which row cause this problem, cause i display the row that did this in my error message. But the problem is that it seems to be ok...
how can i know if it have an invalid data?
i'm trying to update data where i know it can have problem
didn't seems to be the french character... but it's very bugging me
i know which row cause this problem, cause i display the row that did this in my error message. But the problem is that it seems to be ok...
how can i know if it have an invalid data?
i'm trying to update data where i know it can have problem
didn't seems to be the french character... but it's very bugging me
>> cause i display the row that did this in my error message
How?
Try doing
select encode(badcolumn, 'hex') from tablex where id = n
then post the result.
How?
Try doing
select encode(badcolumn, 'hex') from tablex where id = n
then post the result.
ASKER
humm no it's seems to be french character the problem
it could be type by a user that have a french keyboard layout or type in windows with the ascii code, so how can i be able to select it from java with the jdbc?
here is the error message with the stack trace
--------
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.
org.postgresql.jdbc2.Abstr actJdbc2Re sultSet.ge tString(Ab stractJdbc 2ResultSet .java:1830 )
org.postgresql.jdbc2.Abstr actJdbc2Re sultSet.ge tString(Ab stractJdbc 2ResultSet .java:2134 )
JavaTableParser.actionPerf ormed(Java TableParse r.java:185 )
javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1786)
javax.swing.AbstractButton $ForwardAc tionEvents .actionPer formed(Abs tractButto n.java:183 9)
javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:245)
java.awt.Component.process MouseEvent (Component .java:5100 )
java.awt.Component.process Event(Comp onent.java :4897)
java.awt.Container.process Event(Cont ainer.java :1569)
java.awt.Component.dispatc hEventImpl (Component .java:3615 )
java.awt.Container.dispatc hEventImpl (Container .java:1627 )
java.awt.Component.dispatc hEvent(Com ponent.jav a:3477)
java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:3 483)
java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:31 98)
java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3128)
java.awt.Container.dispatc hEventImpl (Container .java:1613 )
java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1606)
java.awt.Component.dispatc hEvent(Com ponent.jav a:3477)
java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:456)
java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:201)
java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :151)
java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 45)
java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 37)
java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:100)
it could be type by a user that have a french keyboard layout or type in windows with the ascii code, so how can i be able to select it from java with the jdbc?
here is the error message with the stack trace
--------
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.
org.postgresql.jdbc2.Abstr
org.postgresql.jdbc2.Abstr
JavaTableParser.actionPerf
javax.swing.AbstractButton
javax.swing.AbstractButton
javax.swing.DefaultButtonM
javax.swing.DefaultButtonM
javax.swing.plaf.basic.Bas
java.awt.Component.process
java.awt.Component.process
java.awt.Container.process
java.awt.Component.dispatc
java.awt.Container.dispatc
java.awt.Component.dispatc
java.awt.LightweightDispat
java.awt.LightweightDispat
java.awt.LightweightDispat
java.awt.Container.dispatc
java.awt.Window.dispatchEv
java.awt.Component.dispatc
java.awt.EventQueue.dispat
java.awt.EventDispatchThre
java.awt.EventDispatchThre
java.awt.EventDispatchThre
java.awt.EventDispatchThre
java.awt.EventDispatchThre
ASKER
ok i'll try the encode
ASKER
didn't work in java with jdbc and in postgresql...
it's not a valide function
ERROR: Function encode(character varying, "unknown") does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
it's not a valide function
ERROR: Function encode(character varying, "unknown") does not exist
Unable to identify a function that satisfies the given argument types
You may need to add explicit typecasts
>>didn't work in java with jdbc and in postgresql...
well i meant to execute that at the db prompt, not from Java
well i meant to execute that at the db prompt, not from Java
ASKER
didn't work in portgresql prompt too
it's the db prompt error message i pasted you
it's the db prompt error message i pasted you
ASKER
dont have cast for hex type and didn't able to create one
Strange - it's certainly here, and i'd *guess* has been around for a while:
http://www.postgresql.com/docs/7.3/interactive/functions-string.html
http://www.postgresql.com/docs/7.3/interactive/functions-string.html
ASKER
ok it work if i supply a text into '' but didn't work if i put the column name without the '' into the function like:
select encode('txt', 'hex') from fdsdb_java where typeforme != '' and txt like '60 degr%'; this work but return the hex of the text txt and not of the text into the colum name txt
and this
select encode(txt, 'hex') from fdsdb_java where typeforme != '' and txt like '60 degr%';
give the error message i posted before
thx for help
select encode('txt', 'hex') from fdsdb_java where typeforme != '' and txt like '60 degr%'; this work but return the hex of the text txt and not of the text into the colum name txt
and this
select encode(txt, 'hex') from fdsdb_java where typeforme != '' and txt like '60 degr%';
give the error message i posted before
thx for help
ASKER
to fix the problem, not really fix, but i need to do something quick, i need to update each row that have a french character (row that jdbc give me error, i presume it's all row with french character), with a non french... so where i have é i put e and where i have à i put a
but i'm still curios on a real solution, could be very usefull to know and could solve my problem really quickly instead of this poor "solution"
thx
but i'm still curios on a real solution, could be very usefull to know and could solve my problem really quickly instead of this poor "solution"
thx
Hmm. Probably could come up with a kludge but what does this return (if anything)?:
select pg_client_encoding() from fdsdb_java
select pg_client_encoding() from fdsdb_java
sounds like the problem may be with the data in your db, not with how you are accessing it.
That's precisely why i'm asking bumpert to dump it as hex
well pardon me for offering a suggestion to what the cause of the problem was!!
anyways see if your hex dump confirms my suspisions
anyways see if your hex dump confirms my suspisions
what platform are you using ?
did you use initdb URDB -E LATIN9
output of psql \l command ?
if you are using windows console CMD.EXE did you set codepage correctly ?
eg C:> CHCP 1252
did you use initdb URDB -E LATIN9
output of psql \l command ?
if you are using windows console CMD.EXE did you set codepage correctly ?
eg C:> CHCP 1252
>>well pardon me for offering a suggestion to what the cause of the problem was!!
Well it would help if it were a new one ;-)
>>
Make sure you haven't got data in there that's invalid (it may be nothing to do with accented characters)
>>
Well it would help if it were a new one ;-)
>>
Make sure you haven't got data in there that's invalid (it may be nothing to do with accented characters)
>>
http://www.postgresql.org/docs/7.3/interactive/multibyte.html
PostgreSQL JDBC driver does not support MULE_INTERNAL, LATIN6, LATIN8, and LATIN10.
PostgreSQL JDBC driver does not support MULE_INTERNAL, LATIN6, LATIN8, and LATIN10.
What version of postgresql are you using?
latest postgresql.jar jdbc driver requires code transformation functions which appeared only recently.
look at Encoding.java
when making postgresql from source make sure --enable-nls is specified E.G.
./configure --prefix=/usr --with-perl --with-python --with-openssl --with-gnu-ld --enable-nls
make
make install
latest postgresql.jar jdbc driver requires code transformation functions which appeared only recently.
look at Encoding.java
when making postgresql from source make sure --enable-nls is specified E.G.
./configure --prefix=/usr --with-perl --with-python --with-openssl --with-gnu-ld --enable-nls
make
make install
you may need to set client session encoding parameter to eliminate bad characters in the future.
SET CLIENT_ENCODING = 'WIN1250';
SET CLIENT_ENCODING = 'WIN1250';
Check the character set of your Database. What is it?
ASKER
>Hmm. Probably could come up with a kludge but what does this return (if anything)?:
>select pg_client_encoding() from fdsdb_java
SQL_ASCII
thx
>select pg_client_encoding() from fdsdb_java
SQL_ASCII
thx
ASKER
> sounds like the problem may be with the data in your db, not with how you are accessing it.
it's what i think now by seeing your post, but the problem is if i acces it from embperl in webpage i have no problem.
And the only data that seems to cause problem are french character, entered by a user with a french keyboard layout or with the ascii code (ex.: ALT + 0233 for é)
thx for help
it's what i think now by seeing your post, but the problem is if i acces it from embperl in webpage i have no problem.
And the only data that seems to cause problem are french character, entered by a user with a french keyboard layout or with the ascii code (ex.: ALT + 0233 for é)
thx for help
Then you should set it to something else. UNICODE or LATIN1
ASKER
>what platform are you using ?
Gentoo Linux
>did you use initdb URDB -E LATIN9
Don't know, it's not me that manage the server, but i don't think so..
>output of psql \l command ?
return my database, with SQL_ASCII
>if you are using windows console CMD.EXE did you set codepage correctly ?
>eg C:> CHCP 1252
I use putty to access my server, but the problem it seems to be only when i tried to retrieve data with jdbc, cause it's working in psql (in putty) and working with embperl in our webpage
thx for help
Gentoo Linux
>did you use initdb URDB -E LATIN9
Don't know, it's not me that manage the server, but i don't think so..
>output of psql \l command ?
return my database, with SQL_ASCII
>if you are using windows console CMD.EXE did you set codepage correctly ?
>eg C:> CHCP 1252
I use putty to access my server, but the problem it seems to be only when i tried to retrieve data with jdbc, cause it's working in psql (in putty) and working with embperl in our webpage
thx for help
I can't find details on SQL_ASCII character set, but i'd guess it doesn't support French characters. See my last comment
ASKER
>What version of postgresql are you using?
7.3.4
>latest postgresql.jar jdbc driver requires code transformation functions which appeared only recently.
i use the lastest from cvs
>look at Encoding.java
i'll check but don't really know what to check
>when making postgresql from source make sure --enable-nls is specified E.G.
>./configure --prefix=/usr --with-perl --with-python --with-openssl --with-gnu-ld --enable-nls
>make
>make install
ok would be good for the future, but i can't reinstall postgre for now
thx for help
7.3.4
>latest postgresql.jar jdbc driver requires code transformation functions which appeared only recently.
i use the lastest from cvs
>look at Encoding.java
i'll check but don't really know what to check
>when making postgresql from source make sure --enable-nls is specified E.G.
>./configure --prefix=/usr --with-perl --with-python --with-openssl --with-gnu-ld --enable-nls
>make
>make install
ok would be good for the future, but i can't reinstall postgre for now
thx for help
ASKER
> you may need to set client session encoding parameter to eliminate bad characters in the future.
>SET CLIENT_ENCODING = 'WIN1250';
ok thx
>SET CLIENT_ENCODING = 'WIN1250';
ok thx
ASKER
> Check the character set of your Database. What is it?
SQL_ASCII
SQL_ASCII
ASKER
> Then you should set it to something else. UNICODE or LATIN1
the database? i could'nt cause i'm not the only user that acces this database.... i hate trying doing things in company where your are limited by too much things.... at home i could do what i want
thx
the database? i could'nt cause i'm not the only user that acces this database.... i hate trying doing things in company where your are limited by too much things.... at home i could do what i want
thx
ASKER
> I can't find details on SQL_ASCII character set, but i'd guess it doesn't support French characters. See my last comment
i think it support, cause my problem was the way i saved my data and now i change my way and it's ok i can se french caracter without problem...
but i need to fix my others table that are wrong
i think it support, cause my problem was the way i saved my data and now i change my way and it's ok i can se french caracter without problem...
but i need to fix my others table that are wrong
>>cause my problem was the way i saved my data
Can you explain this?
Can you explain this?
ASKER
i was adding text into an applet, send the data to a cgi that write the data to a text file and run a java application on the server to retrieve the data and save it into the db.. very complicated but we didn't want to open the 5432 port from outside and i was starting programming :0
thx for help
thx for help
Hmm, but that doesn't account for the problem really ...
ASKER
i know, it's weird cause if i send the data to the cgi and the cgi save it themself i have no problem
The Java that's *writing* to the db may have the wrong encoding set on the driver
ASKER
yes it's why i was thinking, so i changed the way my applet save and now the french caracter is saving well
but i still have problem to retrieve the data that was saved in that poor style
thx for help (sorry for late answer, i wasn't at work for 4 days)
but i still have problem to retrieve the data that was saved in that poor style
thx for help (sorry for late answer, i wasn't at work for 4 days)
>>but i still have problem to retrieve the data that was saved in that poor style
Try reading using the same driver setting as that with which it was saved
Try reading using the same driver setting as that with which it was saved
ASKER
it was the first thing i tried
thx
thx
Post the result of
System.out.println(new sun.misc.HexDumpEncoder(). encode(res ultSet.get Bytes("bad _field"))) ;
System.out.println(new sun.misc.HexDumpEncoder().
If you can work out the character set used you should be able to use convert function to update table column(s).
convert(string using conversion_name)
convert(string using conversion_name)
ASKER
0000: 53 6F 75 64 75 72 65 20 64 27 61 6E 67 6C 65 20 Soudure d'angle
0010: 64 65 20 35 6D 6D 20 73 75 72 20 31 32 30 20 64 de 5mm sur 120 d
0020: 65 67 72 E9 73
0010: 64 65 20 35 6D 6D 20 73 75 72 20 31 32 30 20 64 de 5mm sur 120 d
0020: 65 67 72 E9 73
That output (the method is slightly buggy) is perfect output for French stored in ISO-8859-1. So if you go to the trouble of doing your own decoding, you'll get
Soudure d'angle de 5mm sur 120 degrés
Soudure d'angle de 5mm sur 120 degrés
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
> String s = new String(resultSet.getBytes( "bad_field "), "ISO8859-1");
this solved my problem, please post to this thread and i'll give you others points: https://www.experts-exchange.com/questions/21151155/Invalid-character-data-was-found.html
thx a lot
this solved my problem, please post to this thread and i'll give you others points: https://www.experts-exchange.com/questions/21151155/Invalid-character-data-was-found.html
thx a lot
8-)