pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: LiuYan 刘研 <lovetide@21cn.com>
To: pgsql-jdbc@postgresql.org
Subject: Chinese database name in URL, can I ?
Date: Tue, 23 Oct 2007 08:16:38 -0700 (PDT)
Message-ID: <13366356.post@talk.nabble.com> (raw)


I'm interesting in PostgreSQL these days, I created a database whose name
contains Chinese characters, when I try to connect this database, I got an
error: org.postgresql.util.PSQLException: FATAL: database "??pg???" does not
exist 

I'm using PostgreSQL 8.2.5 on Windows XP SP2 Simplified Chinese system, and
using postgresql-8.2-506.jdbc4.jar as the jdbc driver.

Here is my test Java program:
--------------------------------------------------------------------------------
<%@page pageEncoding="gbk" contentType="text/html" session="false"
import="java.sql.*,java.util.*"%>
<h1>Chinese DatabaseName Test | 中文数据库名测试</h1>
<%
String jdbcDriverName = "org.postgresql.Driver";
String
jdbcURL="jdbc:postgresql://localhost/中文pg数据库?user=root&password=123456";
String jdbcUserName = "root";
String jdbcPassword = "123456";

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
	Class.forName (jdbcDriverName);
	con = DriverManager.getConnection (jdbcURL, jdbcUserName, jdbcPassword);
	stmt = con.createStatement ();
	rs = stmt.executeQuery("select version()");
	ResultSetMetaData rsmd = rs.getMetaData ();

	while (rs.next())
	{
		out.println (rs.getString(1));
	}
	rs.close();
	stmt.close();
	con.close ();
}catch (Exception e) {
	out.println (e);
}
%>
--------------------------------------------------------------------------------


and the database environment:
--------------------------------------------------------------------------------
C:\>psql -U root postgres
Welcome to psql 8.2.5, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

postgres=# \l
            数据库列表
     名字     | 所有者 |   编码
--------------+--------+-----------
 cntestdb     | root   | EUC_CN
 postgres     | root   | SQL_ASCII
 template0    | root   | SQL_ASCII
 template1    | root   | SQL_ASCII
 中文pg_utf8  | root   | UTF8
 中文pg数据库 | root   | EUC_CN
(6 rows)

postgres=# \c 中文pg数据库;
You are now connected to database "中文pg数据库".
中文pg数据库=# \dt;
               关系列表
  模式  |     名字     | 类型 | 所有者
--------+--------------+------+--------
 public | serverregion | 表   | root
 public | servers      | 表   | root
 public | 中文表       | 表   | root
(3 rows)

中文pg数据库=# select * from 中文表;
 字段1 |   字段2
-------+------------
     1 | hello 你好
     2 | pg数据库
     3 | 用jdbc访问
     4 | 中文数据库
     5 | 可以吗?
(5 rows)

中文pg数据库=#
--------------------------------------------------------------------------------

I've also tried add '&charSet=GBK' in the jdbcURL, and got the same result.

I know that MySQL can support Chinese database name in jdbc URL, so how can
I use Chinese database name in jdbc URL to connect PostgreSQL?

Thanks!

-- 
View this message in context: http://www.nabble.com/Chinese-database-name-in-URL%2C-can-I---tf4678108.html#a13366356
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.




view thread (5+ messages)  latest in thread

Message-ID: <13366356.post@talk.nabble.com>
Permalink:  ../13366356.post@talk.nabble.com/
Also on:    postgresql.org/message-id/13366356.post@talk.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: lovetide@21cn.com
  Subject: Re: Chinese database name in URL, can I ?
  In-Reply-To: <13366356.post@talk.nabble.com>
  References: <13366356.post@talk.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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