From: | carmentl12 <hrodriguez(at)facinf(dot)uho(dot)edu(dot)cu> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Problem with client_encoding UTF8 |
Date: | 2012-08-24 18:02:49 |
Message-ID: | 1345831369323-5721132.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hello:
I'm trying to restore a postgres database backup programmatically, I use
JDBC driver (postgresql-9.1-902.jdbc4), and I get the following error,
org.postgresql.util.PSQLException: The server's client_encoding parameter
was changed to UTF8. The JDBC driver requires client_encoding to be UNICODE
for correct operation.
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1366)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:343)
This is my code:
PreparedStatement preparedStatement;
String content = getScriptContents("C:/script.sql"); //here I read the
contents of the script
String[] statements = content.split(";");
//here I execute with preparedStatement each script line, the error shows in
this line
//SET client_encoding = 'UTF8';
for (String string : statements) {
if (!string.equals("")) {
preparedStatement =
currentConnection.getJDBCConnection().prepareStatement(string);
preparedStatement.execute();
preparedStatement.close();
}
}
The database where I want to restore has as encoding UTF8, so I don't know
why appears this error.
I read this posts, but I'm not clear what is the solution that any of you
proposed for this problem:
http://archives.postgresql.org/pgsql-jdbc/2008-02/msg00175.php
http://postgresql.1045698.n5.nabble.com/SET-client-encoding-UTF8-td2174216.html
http://postgresql.1045698.n5.nabble.com/Re-HACKERS-JDBC-connections-to-9-1-td4310977.html
In the third post it is proposed a patch but I'm not sure if this solve the
error and it seems hasn't been included in the driver after all, please I
would really appreciatte if you tell me why this is happening and which is
the solution for it.
One curious thing, I made a test creating the connection like this, and the
error didn't appear, the restore was successful.
Connection connection =
DriverManager.getConnection("jdbc:postgresql://192.168.2.241:5432/demo_desktop",
"user", "pass");
Before I used for create the connection this class
org.netbeans.api.db.explorer.DatabaseConnection (from NetBeans Platform), I
don't understand why with this one appears the error and with
DriverManager.getConnection doesn't.
Thanks in advance,
Carmen
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Problem-with-client-encoding-UTF8-tp5721132.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Shijun Kong | 2012-08-24 20:45:59 | Re: send/receive buffer size |
Previous Message | Craig Ringer | 2012-08-24 02:26:49 | Re: setObject(...) with native Java arrays like String[] ? |