Connection fails when the user name contains chinese characters

From: "Sarkar, Sudipta" <Sudipta_Sarkar(at)bmc(dot)com>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Connection fails when the user name contains chinese characters
Date: 2010-05-17 20:02:21
Message-ID: 2FB1D66ABE14B141BCF3DD40A3D95AD113CFA24BA1@PHXCCRPRD01.adprod.bmc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2010-05-18 02:28:46 Re: Connection fails when the user name contains chinese characters
Previous Message Kris Jurka 2010-05-17 18:06:08 Re: 8.4 vs 8.1 AbstractJdbc2Array - Array retrieval