kcchow
asked on
How to insert simplified chinese character in oracle through JSP
Oracle 8i 8.1.7
IBM RS6000 AIX5L
NLS_LANGUAGE=SIMPLIFIED CHINESE
NLS_TERRITORY=CHINA
NLS_CHARACTERSET=ZHS16GBK
NLS_NCHAR_CHARACTERSET=USA SCII7
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. OracleDriv er"/>
<jsp:setProperty name="SQL" property="jdbcURL" value="jdbc:oracle:oci8:@o ra8"/>
<jsp:setProperty name="SQL" property="username" value="aaaa"/>
<jsp:setProperty name="SQL" property="password" value="bbbb"/>
</jsp:useBean>
<%
String strA = "傖髡載& #38484; 5473;Ɓ 96;蝠 ;眢& #26740;";
String strA1 = new String(strA.getBytes("ISO- 8859-1"), response.getCharacterEncod ing());
%>
Character Encode - <%=response.getCharacterEn coding()%> <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(respo nse.getCha racterEnco ding()), "ISO-8859-1");
%>
Original - <%=strA %><br>
gb2312 to ISO - <%=strA1 %><br>
<p>
<%
}
SQL.closeDB();
%>
IBM RS6000 AIX5L
NLS_LANGUAGE=SIMPLIFIED CHINESE
NLS_TERRITORY=CHINA
NLS_CHARACTERSET=ZHS16GBK
NLS_NCHAR_CHARACTERSET=USA
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.
<jsp:setProperty name="SQL" property="jdbcURL" value="jdbc:oracle:oci8:@o
<jsp:setProperty name="SQL" property="username" value="aaaa"/>
<jsp:setProperty name="SQL" property="password" value="bbbb"/>
</jsp:useBean>
<%
String strA = "傖髡載&
String strA1 = new String(strA.getBytes("ISO-
%>
Character Encode - <%=response.getCharacterEn
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(respo
%>
Original - <%=strA %><br>
gb2312 to ISO - <%=strA1 %><br>
<p>
<%
}
SQL.closeDB();
%>
ASKER
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
By the way, is there any effect if I have using JDK version 1.1.8
Hello kcchow,
Is not possible to use JSP and servlet with JDK 1.1.8. Which is your web container?
regards
Is not possible to use JSP and servlet with JDK 1.1.8. Which is your web container?
regards
ASKER
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....
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....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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