vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I've got another problem. I sometimes get the following SQLException when doing an insert: ERROR: invalid byte sequence for encoding "UTF8": 0x00 Exception: org.postgresql.util.PSQLException org.postgresql.core.v3.QueryExecutorImpl.receiveEr rorResponse(QueryExecutorImpl.java:1525) org.postgresql.core.v3.QueryExecutorImpl.processRe sults(QueryExecutorImpl.java:1309) org.postgresql.core.v3.QueryExecutorImpl.execute(Q ueryExecutorImpl.java:188) org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:452) org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(AbstractJdbc2Statement.java:354) org.postgresql.jdbc2.AbstractJdbc2Statement.execut eUpdate(AbstractJdbc2Statement.java:308) By the way, the insert is done with a PreparedStatement and I use only setLong(), setString(), setTimestamp() and setInt(). I don't understand it very well. It is obviously an encoding exception but I don't know why it happens and what I could do avoid it. Any idea? __________________________________________________ _______________ Opret en personlig blog og del dine billeder på MSN Spaces: http://spaces.msn.com/ ---------------------------(end of broadcast)--------------------------- TIP 1: 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 |
| |||
| Try to change the encoding of your database to "Unicode". I hope this helps. --Altaf Malik EnterpriseDB www.enterprisedb.com James Im <im-james@hotmail.com> wrote: Hi, I've got another problem. I sometimes get the following SQLException when doing an insert: ERROR: invalid byte sequence for encoding "UTF8": 0x00 Exception: org.postgresql.util.PSQLException org.postgresql.core.v3.QueryExecutorImpl.receiveEr rorResponse(QueryExecutorImpl.java:1525) org.postgresql.core.v3.QueryExecutorImpl.processRe sults(QueryExecutorImpl.java:1309) org.postgresql.core.v3.QueryExecutorImpl.execute(Q ueryExecutorImpl.java:188) org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:452) org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(AbstractJdbc2Statement.java:354) org.postgresql.jdbc2.AbstractJdbc2Statement.execut eUpdate(AbstractJdbc2Statement.java:308) By the way, the insert is done with a PreparedStatement and I use only setLong(), setString(), setTimestamp() and setInt(). I don't understand it very well. It is obviously an encoding exception but I don't know why it happens and what I could do avoid it. Any idea? __________________________________________________ _______________ Opret en personlig blog og del dine billeder på MSN Spaces: http://spaces.msn.com/ ---------------------------(end of broadcast)--------------------------- TIP 1: 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 --------------------------------- Don't get soaked. Take a quick peak at the forecast with theYahoo! Search weather shortcut. |
| |||
| James Im wrote: > I've got another problem. I sometimes get the following SQLException > when doing an insert: > > ERROR: invalid byte sequence for encoding "UTF8": 0x00 You're trying to insert a string which contains a '\0' character. The server can't handle strings containing embedded NULs, as it uses C-style string termination internally. -O ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
| |||
| I've had the same error, and it is in fact because in Java you can actually have a "0x0" character in your string, and that's valid unicode. So that's translated to the character 0x0 in UTF8, which in turn is not accepted because the server uses null terminated strings... so the only way is to make sure your strings don't contain the character '\u0000'. I identified the place in my code which was generating such a character and fixed, and I didn't have other problems after that... even if I still think forbidding a valid character is a somewhat arbitrary restriction. HTH, Csaba. On Tue, 2007-02-20 at 11:57, Altaf Malik wrote: > Try to change the encoding of your database to "Unicode". > I hope this helps. > > --Altaf Malik > EnterpriseDB > www.enterprisedb.com > James Im <im-james@hotmail.com> wrote: > Hi, > > I've got another problem. I sometimes get the following > SQLException > when doing an insert: > > ERROR: invalid byte sequence for encoding "UTF8": 0x00 > Exception: org.postgresql.util.PSQLException > org.postgresql.core.v3.QueryExecutorImpl.receiveEr rorResponse(QueryExecutorImpl.java:1525) > org.postgresql.core.v3.QueryExecutorImpl.processRe sults(QueryExecutorImpl.java:1309) > org.postgresql.core.v3.QueryExecutorImpl.execute(Q ueryExecutorImpl.java:188) > org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:452) > org.postgresql.jdbc2.AbstractJdbc2Statement.execut eWithFlags(AbstractJdbc2Statement.java:354) > org.postgresql.jdbc2.AbstractJdbc2Statement.execut eUpdate(AbstractJdbc2Statement.java:308) > > By the way, the insert is done with a PreparedStatement and I > use only > setLong(), setString(), setTimestamp() and setInt(). > > > I don't understand it very well. It is obviously an encoding > exception > but I don't know why it happens and what I could do avoid it. > > Any idea? > > __________________________________________________ _______________ > Opret en personlig blog og del dine billeder på MSN Spaces: > http://spaces.msn.com/ > > > ---------------------------(end of > broadcast)--------------------------- > TIP 1: 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 > > > __________________________________________________ ____________________ > Don't get soaked. Take aquick peak at the forecast > with theYahoo! Search weather shortcut. ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| Oliver Jowett wrote: > James Im wrote: > >> I've got another problem. I sometimes get the following SQLException >> when doing an insert: >> >> ERROR: invalid byte sequence for encoding "UTF8": 0x00 > > You're trying to insert a string which contains a '\0' character. The > server can't handle strings containing embedded NULs, as it uses C-style > string termination internally. > At least on other servers/drivers I believe nulls are supported (and should be according to some spec) (The only special-meaning char is single quote). I'm wondering how the binary protocol works insofar as handling the NULL byte; does it precede it with a backslash? I'm wondering if this would be possible for the String conversion as well -- just for sake of consistency with other DBs (and since some API inevitable expect users to send binary data through a char-sequence interface) ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| |||
| Ken Johanson wrote: > At least on other servers/drivers I believe nulls are supported (and > should be according to some spec) (The only special-meaning char is > single quote). The driver can't do anything about it, it's a server issue. I can think of some ways the server could support it without extensive changes .. e.g. use a "modified UTF8" representation which stores \u0000 as 0xc0 0x80 internally .. but you'd have to take that up with the backend developers. > I'm wondering how the binary protocol works insofar as handling the NULL > byte; does it precede it with a backslash? The driver sends string parameters out-of-line without escaping (i.e. length field, then raw utf-8 data). The error you see is generated when the server notices that there's a \u0000 there; it rejects the string entirely rather than silently mangling it. -O ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
| ||||
| On Feb 22, 2007, at 07:37, Ken Johanson wrote: > At least on other servers/drivers I believe nulls are supported > (and should be according to some spec) (The only special-meaning > char is single quote). Yes. I got this error while copying data from a MS SQL Server to PostgreSQL. - Tore. ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| Thread Tools | |
| Display Modes | |
|
|