pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedProblem with client_encoding UTF8
2+ messages / 1 participants
[nested] [flat]
* Problem with client_encoding UTF8
@ 2012-08-24 18:02 carmentl12 <hrodriguez@facinf.uho.edu.cu>
0 siblings, 1 reply; 2+ messages in thread
From: carmentl12 @ 2012-08-24 18:02 UTC (permalink / raw)
To: 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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Problem with client_encoding UTF8
@ 2012-08-30 14:12 carmentl12 <hrodriguez@facinf.uho.edu.cu>
parent: carmentl12 <hrodriguez@facinf.uho.edu.cu>
0 siblings, 0 replies; 2+ messages in thread
From: carmentl12 @ 2012-08-30 14:12 UTC (permalink / raw)
To: pgsql-jdbc
I found a possible solution: instead of read the contents of the script I
execute it with the command psql like this,
Runtime.getRuntime().exec("psql -U " + user + " -h " + host + " -d " +
dbName + " -f " + path);
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Problem-with-client-encoding-UTF8-tp5721132p5721903.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2012-08-30 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-08-24 18:02 Problem with client_encoding UTF8 carmentl12 <hrodriguez@facinf.uho.edu.cu>
2012-08-30 14:12 ` carmentl12 <hrodriguez@facinf.uho.edu.cu>
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