pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Connection fails when the user name contains chinese characters
2+ messages / 2 participants
[nested] [flat]

* Connection fails when the user name contains chinese characters
@ 2010-05-17 20:02 Sarkar, Sudipta <Sudipta_Sarkar@bmc.com>
  2010-05-18 02:28 ` Re: Connection fails when the user name contains chinese characters Craig Ringer <craig@postnewspapers.com.au>
  0 siblings, 1 reply; 2+ messages in thread

From: Sarkar, Sudipta @ 2010-05-17 20:02 UTC (permalink / raw)
  To: 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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Connection fails when the user name contains chinese characters
  2010-05-17 20:02 Connection fails when the user name contains chinese characters Sarkar, Sudipta <Sudipta_Sarkar@bmc.com>
@ 2010-05-18 02:28 ` Craig Ringer <craig@postnewspapers.com.au>
  0 siblings, 0 replies; 2+ messages in thread

From: Craig Ringer @ 2010-05-18 02:28 UTC (permalink / raw)
  To: Sarkar, Sudipta <Sudipta_Sarkar@bmc.com>; +Cc: pgsql-jdbc

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-05-18 02:28 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-05-17 20:02 Connection fails when the user name contains chinese characters Sarkar, Sudipta <Sudipta_Sarkar@bmc.com>
2010-05-18 02:28 ` Craig Ringer <craig@postnewspapers.com.au>

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