Thread: Connection fails when the user name contains chinese characters
Hi,
I have a postgres 8.3 database with a user name containing Chinese characters 泰山.
When I am trying to connect to the database using this user name it fails with the following message:
Exception in thread "main" org.postgresql.util.PSQLException: FATAL: role "??" does not exist
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:444)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:99)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:29)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:390)
at org.postgresql.Driver.connect(Driver.java:261)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at JDBCTest.main(JDBCTest.java:9)
My code snippet is the following:
Class.forName("org.postgresql.Driver");
Properties connProp = new Properties();
connProp.put("user", "\u6cf0\u5c71"); //Set the user name. Need to use Unicode escaped since it contains non ascii characters
System.out.println("connProp: " + connProp + " " + connProp.getProperty("user"));
Connection conn = DriverManager.getConnection("jdbc:postgresql://172.21.126.56:15432/mydb", connProp);
I even tried with DriverManager.getConnection("jdbc:postgresql://172.21.126.56:15432/mydb", "\u6cf0\u5c71", “”);
Which gives the same error.
Looks like the username is not sent to the server correctly.
I tried to connect to the database using psql –p 15432 –U 泰山 mydb
And the connection was successful.
So the username is correct on the server. The JDBC driver is not sending the user name correctly to the server.
My jdbc version is 8.3-603 and my database encoding is UTF-8.
Thanks
Sudipta
On 18/05/2010 4:02 AM, Sarkar, Sudipta wrote: > connProp.put("user", "\u6cf0\u5c71"); //Set the user name. Need to use > Unicode escaped since it contains non ascii characters What character encoding are your source files in? You should be able to write normal UTF-8 encoded text so long as your compiler/IDE knows that those are UTF-8 source files. > My jdbc version is 8.3-603 and my database encoding is UTF-8. Maybe try the latest JDBC driver (701), just to make sure it's not an old issue... -- Craig Ringer