linux下通过Plone访问Oracle XE(支持中文字段)

来源:互联网 发布:windows怎么开发ios 编辑:程序博客网 时间:2024/05/19 23:02

假定系统中已成功安装了Zope/Plone系统,并拥有可运行的Plone实例。

第一步、安装Oracle数据库。

1、运行

# hostname

确保列出的主机名在/etc/hosts中正确的被配置到127.0.0.1;

2、将以下字句加入到 .bashrc 中:

export ORACLE_BASE=/usr/lib/oracle/xe/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/server
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_HOME_LISTNER=$ORACLE_HOME
export TNS_ADMIN=$ORACLE_HOME
export ORACLE_SID=XE

重新启动机器。

3、下载oracle-xe-10.2.0.1-1.0.i386.rpm,进行如下步骤安装。

# rpm -ivh oracle-xe-univ-10.2.0.1-1.0.i386.rpm Preparing... ########################################### [100%] 1:oracle-xe-univ ########################################### [100%] Executing Post-install steps... You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database. # /etc/init.d/oracle-xe configure Oracle Database 10g Express Edition Configuration ------------------------------------------------- This will configure on-boot properties of Oracle Database 10g Express Edition. The following questions will determine whether the database should be starting upon system boot, the ports it will use, and the passwords that will be used for database accounts. Press <Enter> to accept the defaults. Ctrl-C will abort. Specify the HTTP port that will be used for Oracle Application Express [8080]:10080 Specify a port that will be used for the database listener [1521]: Specify a password to be used for database accounts. Note that the same password will be used for SYS and SYSTEM. Oracle recommends the use of different passwords for each database account. This can be done after initial configuration: *****Confirm the password: *****Do you want Oracle Database 10g Express Edition to be started on boot (y/n) : nStarting Oracle Net Listener...Done Configuring Database...Done Starting Oracle Database 10g Express Edition Instance...Done Installation Completed Successfully. To access the Database Home Page go to http://127.0.0.1:10080/apex

安装时如未设定启动系统时自动启动Oracle,则在系统重启后需要手动启动,如下所示:

# su oracle
$ lsnrctl start

期间如无报错信息,则Oracle实例监听服务已成功启动,可通过查看相应监听端口(默认1521)是否已打开确认。

$ sqlplus / as sysdba
SQL> startup;
SQL> exit;

期间如无报错信息,则Oracle实例以及apex服务均已成功启动,可通过查看相应apex管理端口(默认8080)是否已打开确认。

$ exit

第二步、安装cx_Oracle。

下载cx_Oracle-5.0.2.tar.gz,上传到服务器上之后运行如下命令。

# tar -xzf cx_Oracle-5.0.2.tar.gz
# cd cx_Oracle-5.0.2
# python setup.py build
# python setup.py install

过程中如无报错信息,则说明cx_Oracle已经正确安装,可通过如下操作确认。

[root@sub2 ~]# python
Python 2.4.1 (#1, Dec  7 2006, 18:32:27)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle;
>>> db = cx_Oracle.connect('system','yourpass','XE')
>>> print db.dsn
XE

第三步、安装ZcxOralceDA。

下载ZcxOracleDA-0.5.tar.gz,上传到服务器的Plone实例产品目录下之后运行如下命令。

# tar -xzf ZcxOracleDA-0.5.tar.gz
# chown -R zope:zope ZcxOracleDA/

然后重新启动Zope实例,进入Plone网站Web管理页面看是否能创建ZcxOracle Connection。

第四步、修改字符集

本文中安装的Oracle XE缺省字符集为WE8MSWIN1252,不是中文字符集,所有向数据表的字段中写入中文的尝试只会写入乱码。

而Oracle XE中又不能通过直接运行 alter database character set *******; 来修改字符集,目前经测试确认唯一好用的修改字符集办法如下:

1、将以下字句加入到 .bashrc 中:

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"

2、手动进行如下操作:

# su oracle
$ sqlplus / as sysdba
SQL> select VALUE$ from PROPS$ where NAME='NLS_CHARACTERSET';
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter system enable restricted session;
SQL> alter system set JOB_QUEUE_PROCESSES=0;
SQL> alter system set AQ_TM_PROCESSES=0;
SQL> alter database open;
SQL> alter database character set internal_use AL32UTF8;
SQL> shutdown immediate;
SQL> startup;
SQL> select VALUE$ from PROPS$ where NAME='NLS_CHARACTERSET';
SQL> exit;
$ exit
# reboot

期间对比两次查询结果即可确认字符集是否已成功更改。

重新启动机器后即可测试Zope下相关Oracle应用是否支持UTF8编码的中文录入。

注意:修改字符集后,如果zope在Oracle服务启动之前已经启动,则在Oracle服务启动后,应将Zope服务停止(stop),再将Zope服务开始(start)——注意不是重新开始(restart)——才能够正常连接到Oracle数据库。

遗留问题:

修改字符集后,无法进入apex的WEB管理界面。仍然存在相应端口,但是访问时会报告如下错误:

Unable to run page sentry in application 4500.

来源:http://beauty.hit.edu.cn/myStudy/Platform/document.2009-12-06.6797135224

原创粉丝点击