Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to insert simplified chinese character in oracle through JSP

Posted on 2003-10-26
6
Medium Priority
?
2,570 Views
Last Modified: 2008-02-07
Oracle 8i 8.1.7
IBM RS6000 AIX5L
NLS_LANGUAGE=SIMPLIFIED CHINESE
NLS_TERRITORY=CHINA
NLS_CHARACTERSET=ZHS16GBK
NLS_NCHAR_CHARACTERSET=USASCII7

I have tried to update a field (varchar(100) or varchar2(100)) with simplified chinese character through JSP but failed ('????' are shown). Please help!

Here is my code:

<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.net.*" %>
<%@ page import="beans.*" %>
<jsp:useBean id="SQL" scope="request" class="beans.SQLConnection">
<jsp:setProperty name="SQL" property="driverName" value="oracle.jdbc.driver.OracleDriver"/>
<jsp:setProperty name="SQL" property="jdbcURL" value="jdbc:oracle:oci8:@ora8"/>
<jsp:setProperty name="SQL" property="username" value="aaaa"/>
<jsp:setProperty name="SQL" property="password" value="bbbb"/>
</jsp:useBean>
<%
      String strA = "&#20630;&#39649;&#36617;&#38484;&#35473;&#38596;&#34656;&#30498;&#26740;";
      String strA1 = new String(strA.getBytes("ISO-8859-1"), response.getCharacterEncoding());
      
%>      
Character Encode - <%=response.getCharacterEncoding()%><br>
Original - <%=strA %><br>
ISO to gb2312 - <%=strA1 %><br>
<p>
<%      

            SQL.openDB();
            
            String strsql = "UPDATE testtable SET f1 = '" + strA1 +"'";
            String[] SQLstmts = new String[1];
            SQLstmts[0] = strsql;
            SQL.execUpdate(SQLstmts);
      %>
0 - <%=strsql %><p>
<h1>RESULT</h1>
<%
            strsql = "SELECT f1 FROM testtable";
            SQL.execSQL(strsql);


            while(SQL.nextRow())
            {

                  strA = SQL.getField("f1");
                  strA1 = new String(strA.getBytes(response.getCharacterEncoding()), "ISO-8859-1");


%>
Original - <%=strA %><br>
gb2312 to ISO - <%=strA1 %><br>
<p>
<%
            }

            SQL.closeDB();
%>
      

0
Comment
Question by:kcchow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 3

Expert Comment

by:krispols
ID: 9631887
hello kcchow,

With Oracle to support unicode, you must use UTF-8 charset.
Go and see this link http://otn.oracle.com/products/oracle8i/pdf/ecomwp.pdf

regards
0
 

Author Comment

by:kcchow
ID: 9633404
Thank you krispols. But I need to use ZHS16GBK for the database.
 By the way, is there any effect if I have using JDK version 1.1.8
0
 
LVL 3

Expert Comment

by:krispols
ID: 9639886
Hello kcchow,

Is not possible to use JSP and servlet with JDK 1.1.8. Which is your web container?

regards
0
 

Author Comment

by:kcchow
ID: 9672643
Problem solved. I have added the NLS_LANG=AMERICAN_AMERICA.ZHS16GBK in jserv.properties.

By the way, I have tried to add NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" but error "Invalid NLS parameter values" shown. I seems that NLS_LANGUAGE and NLS_TERRITORY must be in default value in jserv.properties....
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10784959
PAQed, with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question