From: | LiuYan 刘研 <lovetide(at)21cn(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Chinese database name in URL, can I ? |
Date: | 2007-10-23 15:16:38 |
Message-ID: | 13366356.post@talk.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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:
--------------------------------------------------------------------------------
<%(at)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-10-23 15:59:49 | Re: Chinese database name in URL, can I ? |
Previous Message | Robert Wimmer | 2007-10-23 14:53:32 | update custom types via resultset |