Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B5ED79FC359 for ; Wed, 24 Oct 2007 11:03:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 14394-01 for ; Wed, 24 Oct 2007 11:02:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 206759FC470 for ; Wed, 24 Oct 2007 11:03:22 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IkgpM-0006bG-Qg for pgsql-jdbc@postgresql.org; Wed, 24 Oct 2007 07:03:20 -0700 Message-ID: <13384678.post@talk.nabble.com> Date: Wed, 24 Oct 2007 07:03:20 -0700 (PDT) From: =?UTF-8?Q?LiuYan_=E5=88=98=E7=A0=94?= To: pgsql-jdbc@postgresql.org Subject: Re: Chinese database name in URL, can I ? In-Reply-To: <471E8085.8030308@opencloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: lovetide@21cn.com References: <13366356.post@talk.nabble.com> <19162.1193155189@sss.pgh.pa.us> <471E8085.8030308@opencloud.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.998 tagged_above=0 required=5 tests=AWL=0.968, BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, WHOIS_MYPRIVREG=1.499 X-Spam-Level: X-Archive-Number: 200710/129 X-Sequence-Number: 17701 Thanks for your reply Oliver & Tom, You are right. I downloaded the source code of postgresql-jdbc-8.2-506, and found that org.postgresql.core.v3.ConnectionFactoryImpl.java using the hard coded "US-ASCII" to transform the encoding of jdbc parameter names and values. So, a GBK encoded Chinese character(2 bytes) will be transformed to a hex value 0x3F, which is a '?' character. I tried to add a URL parameter "jdbcURLEncoding" in org.postgresql.core.v3.ConnectionFactoryImpl.java to resolve this problem, and it seems works ok for me now(Chinese database name/username /password i= n the jdbc URL) for this testing purpose. But there are too many "US-ASCII"s in the source codes (from database name/username/password to MD5Digest, UnixCrypt, Encoding etc...), so there must be some other things to be concerned which I don't know where/how to do it. The attachments are the two file which I modified: org.postgresql.core.v3.ConnectionFactoryImpl.java org.postgresql.util.MD5Digest.java The following is the new test code: ----------------------------------------- import java.sql.*; public class PgTest { =09public static void main (String[] args) throws Exception =09{ =09=09// =E4=B8=AD=E6=96=87pg=E6=95=B0=E6=8D=AE=E5=BA=93: \u4e2d\u6587pg\u6= 570\u636e\u5e93 =09=09// chineseusername=E4=B8=AD=E6=96=87=E7=94=A8=E6=88=B7=E5=90=8D: chin= eseusername\u4e2d\u6587\u7528\u6237\u540d =09=09// chinesepassword=E4=B8=AD=E6=96=87=E5=AF=86=E7=A0=81: chinesepasswo= rd\u4e2d\u6587\u5bc6\u7801 =09=09String jdbcDriverName =3D "org.postgresql.Driver";=20 =09=09String jdbcURL =3D"jdbc:postgresql://192.168.1.6/\u4e2d\u6587pg\u6570\u636e\u5e93?user=3Dc= hineseusername\u4e2d\u6587\u7528\u6237\u540d&password=3Dchinesepassword\u4e= 2d\u6587\u5bc6\u780d&jdbcURLEncoding=3DGBK"; =09=09Connection con =3D null;=20 =09=09Statement stmt =3D null;=20 =09=09ResultSet rs =3D null;=20 =09=09try {=20 =09=09 Class.forName (jdbcDriverName);=20 =09=09 con =3D DriverManager.getConnection (jdbcURL);=20 =09=09 stmt =3D con.createStatement ();=20 =09=09 rs =3D stmt.executeQuery("select version()");=20 =09=09 ResultSetMetaData rsmd =3D rs.getMetaData ();=20 =09=09 while (rs.next())=20 =09=09 {=20 =09=09 System.out.println (rs.getString(1));=20 =09=09 }=20 =09=09 rs.close();=20 =09=09 stmt.close();=20 =09=09 con.close ();=20 =09=09}catch (Exception e) {=20 =09=09 System.out.println (e);=20 =09=09}=20 =09} } ----------------------------------------- and the following is the DEBUG output produced by modified postgresql jdbc driver. -------------------------------------------- F:\Software\Development\PostgreSQL\psqlJDBC\postgresql-jdbc-8.2-506.src>jav= a -classpath .;jars\postgresql.jar PgTest 21:35:44.937 (1) PostgreSQL 8.2 JDBC4 with SSL (build 506) 21:35:44.968 (1) Trying to establish a protocol version 3 connection to 192.168.1.6:5432 21:35:45.000 (1) FE=3D> StartupPacket(user=3Dchineseusername=E4=B8=AD=E6= =96=87=E7=94=A8=E6=88=B7=E5=90=8D, database=3D=E4=B8=AD=E6=96=87pg=E6=95=B0=E6=8D=AE=E5=BA=93, client_encoding= =3DUNICODE, DateStyle=3DISO) 21:35:45.015 (1) Using GBK charset encoding to encode parameters 21:35:45.031 (1) encodedParams hex dump: 21:35:45.031 (1) user-->75 73 65 72 21:35:45.031 (1) chineseusername=E4=B8=AD=E6=96=87=E7=94=A8=E6=88=B7=E5= =90=8D-->63 68 69 6e 65 73 65 75 73 65 72 6e 61 6d 65 d6 d0 ce c4 d3 c3 bb a7 c3 fb 21:35:45.031 (1) database-->64 61 74 61 62 61 73 65 21:35:45.046 (1) =E4=B8=AD=E6=96=87pg=E6=95=B0=E6=8D=AE=E5=BA=93-->d6 d0 = ce c4 70 67 ca fd be dd bf e2 21:35:45.046 (1) client_encoding-->63 6c 69 65 6e 74 5f 65 6e 63 6f 64 69 6e 67 21:35:45.046 (1) UNICODE-->55 4e 49 43 4f 44 45 21:35:45.046 (1) DateStyle-->44 61 74 65 53 74 79 6c 65 21:35:45.046 (1) ISO-->49 53 4f 21:35:46.031 (1) <=3DBE AuthenticationOk 21:35:46.046 (1) <=3DBE ParameterStatus(client_encoding =3D UNICODE) 21:35:46.046 (1) <=3DBE ParameterStatus(DateStyle =3D ISO, YMD) 21:35:46.046 (1) <=3DBE ParameterStatus(integer_datetimes =3D off) 21:35:46.062 (1) <=3DBE ParameterStatus(is_superuser =3D off) 21:35:46.062 (1) <=3DBE ParameterStatus(server_encoding =3D EUC_CN) 21:35:46.062 (1) <=3DBE ParameterStatus(server_version =3D 8.2.5) 21:35:46.062 (1) <=3DBE ParameterStatus(session_authorization =3D chineseusername=E4=B8=AD=E6=96=87=E7=94=A8=E6=88=B7=E5=90=8D) 21:35:46.062 (1) <=3DBE ParameterStatus(standard_conforming_strings =3D of= f) 21:35:46.062 (1) <=3DBE ParameterStatus(TimeZone =3D Asia/Hong_Kong) 21:35:46.062 (1) <=3DBE BackendKeyData(pid=3D3360,ckey=3D2007175982) 21:35:46.062 (1) <=3DBE ReadyForQuery(I) 21:35:46.078 (1) compatible =3D 8.2 21:35:46.078 (1) loglevel =3D 2 21:35:46.078 (1) prepare threshold =3D 5 getConnection returning driver[className=3Dorg.postgresql.Driver,org.postgresql.Driver@1bf73fa] 21:35:46.140 (1) simple execute, handler=3Dorg.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandle= r@f3d6a5, maxR ows=3D0, fetchSize=3D0, flags=3D17 21:35:46.140 (1) FE=3D> Parse(stmt=3Dnull,query=3D"select version()",oids= =3D{}) 21:35:46.140 (1) FE=3D> Bind(stmt=3Dnull,portal=3Dnull) 21:35:46.140 (1) FE=3D> Describe(portal=3Dnull) 21:35:46.156 (1) FE=3D> Execute(portal=3Dnull,limit=3D0) 21:35:46.156 (1) FE=3D> Sync 21:35:46.281 (1) <=3DBE ParseComplete [null] 21:35:46.281 (1) <=3DBE BindComplete [null] 21:35:46.281 (1) <=3DBE RowDescription(1) 21:35:46.281 (1) <=3DBE DataRow 21:35:46.281 (1) <=3DBE CommandStatus(SELECT) 21:35:46.296 (1) <=3DBE ReadyForQuery(I) PostgreSQL 8.2.5 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.2 (mingw-special) 21:35:46.312 (1) FE=3D> Terminate -------------------------------------------- Oliver Jowett wrote: >=20 > Tom Lane wrote: >> =3D?UTF-8?Q?LiuYan_=3DE5=3D88=3D98=3DE7=3DA0=3D94?=3D writes: >>> I've also tried add '&charSet=3DGBK' in the jdbcURL, and got the same >>> result. >>=20 >> At a guess, the name of the database will have to be in UTF8. I doubt >> that JDBC will think it should do any character set conversion on it. >=20 > IIRC the last time I raised the issue of the encoding used for things=20 > like database names & usernames in the startup packet the answer boiled= =20 > down to "don't use anything but 7-bit ASCII". So the driver sends those= =20 > strings as 7-bit ASCII (i.e. String.getBytes("US-ASCII")). If you've got= =20 > a database name or username that can't be represented using only 7-bit=20 > ASCII, you're out of luck. >=20 > Has something changed here so that non-7-bit data in the startup packet= =20 > will work? >=20 > -O >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >=20 >=20 http://www.nabble.com/file/p13384678/postgresql-jdbc-8.2-506-modified%252Bt= est.zip postgresql-jdbc-8.2-506-modified%2Btest.zip=20 --=20 View this message in context: http://www.nabble.com/Chinese-database-name-i= n-URL%2C-can-I---tf4678108.html#a13384678 Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.