Connection fails when the user name contains chinese characters

Поиск
Список
Период
Сортировка
От Sarkar, Sudipta
Тема Connection fails when the user name contains chinese characters
Дата
Msg-id 2FB1D66ABE14B141BCF3DD40A3D95AD113CFA24BA1@PHXCCRPRD01.adprod.bmc.com
обсуждение исходный текст
Ответы Re: Connection fails when the user name contains chinese characters  (Craig Ringer <craig@postnewspapers.com.au>)
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: 8.4 vs 8.1 AbstractJdbc2Array - Array retrieval
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Connection fails when the user name contains chinese characters