Insert chinese characters in oracle81 database(with code here)
Hi all,
I have problem on insert chinese characters in oracle8i database(with code below). But no problem when display chinese characters in HTML( not include in the follow program)
Can anyone help me?????
In unix:
Database setting:
charset: ZHT16BIG5
version:8.1.7
In NT 4.0 with SP5:
web/app server setting
webserver: iWs4.0.1
appserver: iAs6.0
Java 1.2.2 with download classes12.zip/nls_charset12.zip
JDBC thin driver
code:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import java.lang.*;
import java.lang.reflect.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.math.*;
import oracle.sql.*;
public class updatedata extends HttpServlet
Connection dbCon = null;
ResultSet rs = null;
DataSource ds1 = null;
String input_data = "";
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException{
input_data = req.getParameter("chinese_input");
res.setContentType("text/html; charset=BIG5");
PrintWriter out = res.getWriter();
// draw a table
ConnDB(out);
DrawTable(out);
public void JDBC(PrintWriter out) throws NamingException {
InitialContext ctx = null;
String dsName1 = null;
Connection conn = null;
dsName1 = "jdbc/project";
try {
ctx = new InitialContext();
ds1 = (DataSource)ctx.lookup(dsName1);
}catch (NamingException e) {
out.println("exception in servlet in JDBC : " + e.toString());
/** big5 to unicode conversion **/
private String b2u(String str2convert)
throws IOException {
StringBuffer buffer = new StringBuffer();
byte[] targetBytes = str2convert.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(targetBytes);
InputStreamReader isr=new InputStreamReader(stream, "BIG5");
Reader in = new BufferedReader(isr);
int chInt;
while ( (chInt = in.read()) > -1 ) {
buffer.append((char)chInt);
in.close();
return buffer.toString();
private void DrawTable(PrintWriter out){
try{
try{
// update data
String u="update test_chinese set chinese_script=? where prod_cd=?";
String sProd = "T1";
PreparedStatement ps = dbCon.prepareStatement(u);
ps.setString(1, input_data);
ps.setString(2, sProd);
ps.executeUpdate();
dbCon.commit();
catch(SQLException e){
out.println("exception in insert: " + e.toString());
out.println("<html>");
out.println("<body>");
out.println("update success!!!!");
out.println("</body>");
out.println("</html>");
catch(Exception e){
out.println("exception in servlet in statement: " + e.toString());
private Connection ConnDB(PrintWriter out){
try{
try{
JDBC(out);
catch (Exception e) {
out.println("Database connect failed (init)");
out.println(e.toString());
return null;
dbCon = ds1.getConnection();
catch(Exception e){
out.println("exception in servlet in connection: " + e.toString());
return dbCon;
public void destroy() {
//Close database connection
try {
dbCon.close();
catch (Exception e) {
System.out.println("Error closing database (destroy)");
System.out.println(e.toString());
Hi, Jenny,
When you said unable to insert to database, do you mean you get all ? marks in the database or garbage characters in the database?
? marks mean there are some byte chop off, and garbage characters mean the bytes are ok, just encoding problem.
--Lichu
Similar Messages
-
How to Insert Chinese characters in Japanese Database
Hi all,
I am having following characteristics on my computer
Machine OS --Windows Server 2003
OS language --Japanese
Oracle
Oracle9i Release 9.2.0.1.0 - Production
NLS_LANGUAGE JAPANESE
NLS_CHARACTERSET JA16SJIS
Now, i want to insert into database chinese characters. Please guide me how to do the following thing.
How to insert chinese characters on local machine and if i want to insert on the remote databse (i can not create database link for remote database). I have to send batch file or SQL file and they will execute it on their side.
if i use this command
alter session set nls_language = "SIMPLIFIED CHINESE"
and then insert the records and revert back to japanese character set. Is this correct way....?
Thanks in advance,
PalAs dombrooks has pointed out, unless all the Chinese characters you are trying to store can be represented in the Shift-JIS character set, which seems unlikely, but I'm not an expert on East Asian languages and I believe there are some glyphs that are shared between various languages, then you're not going to be able to store this data in this database in CHAR or VARCHAR2 columns.
Depending on the national character set, you may be able to store the data in NCHAR/ NVARCHAR2 columns, though using these data types can substantially increase application complexities since various languages and libraries don't support NCHAR/ NVARCHAR2 columns or require you to jump through some hoops to use them. Your applications would also have to support both character sets, so your applications would all have to be Unicode enabled most likely, which is certainly possible but it may not be a trivial change.
Justin -
Issue of inserting greek characters into Oracle database using ICAN505
Hi All,
We are currently facing an issue of inserting greek characters into Oracle database using ICAN505.
We receive a file containing greek characters.The values from the file should be inserted into the database.We are reading the file using file OTD with default encoding.
The file can contain english characters too other than greek characters.
The database NLS_CHARACTERSET is AL32UTF8.
When I insert using an insert statement directly ,the values get inserted properly into the DB table.
Inserting the same values using code results in improper characters getting inserted into the table in the database.
Please help....
Thanks in advance !!Globalization forum?
Globalization Support
It works for SQL Developer, which does not depend on NLS_LANG, so I suspect a problem with your NLS settings. -
Insert chinese characters to mysql
I have searched the forum and found a useful links --http://forum.java.sun.com/thread.jspa?threadID=530358 about inserting chinese characters to mysql. However, I can't see the chinese characters displayed in the db. The charset and collation of my table are utf8 and utf8_bin respectively. Can anyone help me? Below is my source code
------------------ Servet ---------------------
package test;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testServlet extends HttpServlet {
private Connection conn;
public void init(ServletConfig config) throws ServletException {
sSysPhyPath = config.getServletContext().getRealPath("/");
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
// set content type and other response header fields first
res.setContentType("text/html");
// get the communication channel with the requesting client
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<body>");
req.setCharacterEncoding("UTF-8");
sValue = req.getParameter("s1");
out.println(sValue.getBytes("UTF-8") + "<br>");
DBConnection objConn = new DBConnection(sSysPhyPath);
try {
conn = objConn.get();
objConn.execQuery(conn, "insert into TBL_test (test_desc) values ('" + sValue.getBytes("UTF-8") + "')");
catch(Exception e) {
e.printStackTrace();
objConn.closeConnection(conn);
out.println("</body></html>");
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
doGet(req, res);
public void destroy() {
--------------- Html ------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#666666">
<form name="test" method="post" action="testServlet">
<input type="text" name="s1">
<input type="Submit" name="Submit" value="Submit">
</form>
</body>
</html>
Besides, if I code the chinese characters directly in the servlet page, what is the encoding of the chinese characters by default? Is it related to my OS locale?
Thanks a lot.objConn.execQuery(conn, "insert into TBL_test
st (test_desc) values ('" + sValue.getBytes("UTF-8")
+ "')");You would be better off using a PreparedStatement and parameters. This will let the MySQL JDBC driver take care of the required encoding. -
Is it possible to insert data into a MySQL database with Java?
Hello everyone!
I would like to know, if it's possible to insert data into a MySQL database, with a JFrame inside a servlet?
When the JFrame is first created it calls this method:
* Connects the servlet with the MySQL database.
private void connect(){
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/data", "root", "omfg123");
}catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
}catch(SQLException sqle){
sqle.printStackTrace();
}Then, when you click the "Add" button, it executes this code:
add.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae){
String employee = employeeName.getText();
String[] args = employee.split(" ");
firstName = args[0];
lastName = args[1];
execute();
});And this is my "execute()" method:
* Connects the servlet with the MySQL database.
* - And executes the SQL queries.
private void execute(){
try{
PreparedStatement statement = connection.prepareStatement("insert" +
" into employees values(" + firstName + ", " + lastName
+ ")");
ResultSet result = statement.executeQuery();
String fullName = firstName + " " + lastName;
printer.write("Employee " + fullName + " added.</br>");
}catch(SQLException sqle){
sqle.printStackTrace();
}But when I click the "Add" button, nothing happens.This is what I use to insert into mysql. It works on windows.
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://" + loadip + "/custsig?" +
"user=root&password=";
Connection con = DriverManager.getConnection(connectionUrl);
newproc = jTextField1.getText();
newsoft = jTextField2.getText();
newdeb = jTextField3.getText();
newcust = jTextField4.getText();
if (newcust.equals("")) {
errorsig12 = 1;
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
} else if (newsoft.equals("")) {
errorsig12 = 1;
jLabel2.setForeground(new java.awt.Color(0, 0, 0));
} else if (newproc.equals("")) {
errorsig12 = 1;
jLabel3.setForeground(new java.awt.Color(0, 0, 0));
} else if (newdeb.equals("")) {
errorsig12 = 1;
jLabel4.setForeground(new java.awt.Color(0, 0, 0));
if (errorsig12 == 0) {
PreparedStatement ps = con.prepareStatement("insert into customer set cust_name = ?, software = ?, processor = ?, debit = ?");
ps.setString(4, newdeb);
ps.setString(3, newproc);
ps.setString(2, newsoft);
ps.setString(1, newcust);
int rs = ps.executeUpdate();
} catch (SQLException eg) {
System.out.println("SQL Exception: " + eg.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: " + cE.toString());
} -
Problem to insert Chinese Characters(GB3212) into MySQL
I met a problem to insert Chinese Characters (GB3212) into MySQL using Entity Bean (or JPA).
For example, when a hardcoded string "{color:#ff0000}电器me元件{color}" is inserted, it is displayed as "{color:#ff0000}??me??{color}" in MySQL.
The NamedQuery is also not working for Chinese Characters.
The setting are as following:
GlassFish JDBC connection pool: useUnicode=true, charecterEncoding=gb2312
NetBeans IDE: source encoding set to GB2312;
MySql table: the column set to CHARACTER SET gb2312;
Any experts, please give advice
Thanks lotI didn't noticed that there is a {color:#ff0000}sun-resources.xml{color} file under {color:#ff0000}<ejb project>/server resources{color}.
This file has a pool configuration. This config just overwite the paremeter i added using Admin Console every time a client is lauched. So there are two option to fix this problem.
1. Insert the follwowing two lines into the {color:#ff0000}sun-resources.xml{color}
<property name="characterEncoding" value="gb2312"/>
<property name="useUnicode" value="true"/>
2. delete the everthing in the {color:#ff0000}sun-resources.xml, using Admin Console {color}config your own pool & DataSource
I tried first option & it works. -
How to insert chinese characters in a table use FDK?
Hello~~
I am expecting to insert chinese characters in an XML file's table.
I'm using FDK7.2, if i use:
F_ApiAddText(docId, &tRange.beg, "asdf");
The English letters "asdf" can be insert correctly in the right place,
But, if insert chinese characters like this:
F_ApiAddText(docId, &tRange.beg, "人们");
No characters insert.
How can i solve this problem?
Please advise
Thanks
zhaopengZhaopeng,
Which encoding are you using for the Chinese characters? FrameMaker 7.2 does not support Unicode or UTF-8. I have not done this before, but I guess you need to supply the characters in Big5 resp. GBK encoding, see
http://help.adobe.com/en_US/FrameMaker/8.0/chinese_korean.pdf
[Ignore the 8.0 in the URL, the document talks about FrameMaker 7]
You also may have to make sure the paragraph format at your text location uses a Chinese font before inserting characters.
- Michael -
Unable to insert Chinese characters in Database
My problem is that I am not able to insert chinese
(to traditional chinese) characters into my tables in the
database.
I have changed the character set to UTF8 while creating the
database and also tried the alter session command in SQL to
alter the NLS_LANGUAGE and NLS_TERRITORY (to say traditional chinese).
But this did not solve my problem.
Also tried all possibilites like getting Chinese characters
in my notepad by copy - paste from a Chinese web site
but while giving the insert into command in my database
it takes some junk values.
Someone PLEASE HELP!!!URGENT!!!
Thanks in advance.
RKP
nullYou mentioned in your first note that you have set your database character set to UTF-8? If so, then you are able to store and retrieve multilingual data, including Chinese and Japanese characters. Your issue is not the database. Your client OS must be able to support these languages as well. It is likely that your version of OS supports only Latin and Western European characters. By the way changing your NT regional setting only effects sorting, date formats etc. It doesn't help you change the languages that your keyboard will support.
1.To determine your Win32 operating system's current ANSI CodePage (ACP). This can be found by bringing up the registry editor (Start --> Run..., type "regedit.exe", and click "OK") and looking at the
registry entry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP (there are many registry entries with very similar names, so please make sure that you are looking at the right place in the registry).
2.To find the character set in the table below based on the ACP you got above.
ANSI CodePage (ACP) Client character set (3rd part of NLS_LANG) (*1)
1250 EE8MSWIN1250
1251 CL8MSWIN1251
1252 WE8MSWIN1252
1253 EL8MSWIN1253
1254 TR8MSWIN1254
1255 IW8MSWIN1255
1256 AR8MSWIN1256
1257 BLT8MSWIN1257
1258 VN8MSWIN1258
874 TH8TISASCII
932 JA16SJIS
936 ZHS16GBK
949 KO16MSWIN949
950 ZHT16MSWIN950
others UTF8 (*2)
(*1) The character sets listed here are compatible with Win32's non-Unicode graphical user interface (GUI). Since Win32's MSDOS Box (Command Prompt) uses different character sets, NLS_LANG needs to be manually set in the MSDOS Box (or set in a batch script) in order to handle the difference
between Win32's GUI and MSDOS Box. (Please see "NLS_LANG Settings in MS-DOS Mode and Batch Mode" in the Oracle8i Installation Guide Release 2 (8.1.6) for Windows NT, part# A73010-01.)
(*2) If you use UTF8 for the 3rd part of NLS_LANG on Win32, client programs that you can use on this operating system would be limited to the ones that explicitly support this configuration. Recent versions of Oracle Forms' Client/Server mode (Fat-Client) on NT4.0 would be an example of such client
programs. This is because the user interface of Win32 is not UTF8, therefore the client programs have to perform explicit conversions between UTF8 (used in Oracle side) and UTF16 (used in Win32 side). -
hi
I have my Database with UTF-8 characterset.
I have sql file that contains data in chinese characters.
I need to run this sql and insert data into my database tables.
The sql file is simple text file saved in UTF-8 encoding.
Do I need to install chinese font on my machine to be able to run the sql successfully?
My nls_lang setting is AMERICAN_AMERICA.UTF8.
kelvinWhat is your operating system characterset? What is your database's operating system? What version of Oracle do you use?
-
Problem with chinese characters while sending mail with .CSV attachment
Hi,
i am sendin .CSV file as an attachment with mail using "SO_DOCUMENT_SEND_API1" FM,
whle opening the mail attachment the chinese characters are not displaying properly.
currently i am using ECC 5.0
can any body help in this regard.
Thanks,
RahimHi Kang Ring,
please convert the content of the attachement into the binary format and then add it as a mail attachment.
LOOP AT i_data ASSIGNING <wa_data>.
if s_output is INITIAL.
CONCATENATE <wa_data> cl_abap_char_utilities=>cr_lf into s_output.
else.
CONCATENATE s_output <wa_data> INTO s_output SEPARATED BY cl_abap_char_utilities=>cr_lf.
endif.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = s_output
IMPORTING
buffer = x_output.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = x_output
TABLES
binary_tab = imail_att.
OR
please use ABAP-Object classes like CL_BCS , CL_document_BCS.....
please findthe below sample code.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = s_output
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = s_output_binary "(of type solix_tab)
ev_size = size ).
attachment->add_attachment( "attachment of type ref to cl_document_bcs
i_attachment_type = 'xls'
i_attachment_subject = l_subject
i_attachment_size = size
i_att_content_hex = s_output_binary ).
you need to write the code for adding the receipents, subject and adding this "attachment " as an attachment to the mail.
Hope this will helps to you....,
thanks,
Rahim. -
Inserting JAPANESE characters in a database
Can somebody please let me know how to insert the JAPANESE (Kanji) Characters into the Database.
Database Version: Oracle 9.2.0.1.0
Paremeters Setting:
NLS_CHARACTERSET - UTF8
NLS_NCHAR_CHARACTERSET - UTF8
Server OS: Win2K
Client OS: Win2KNot sure what your overall requirements from an application
support standpoint. But a simple way would be to use UNIST.
Here is a description:
UNISTR takes as its argument a string and returns it in the national character set.The national character set of the database can be either AL16UTF16 or UTF8.
UNISTR provides support for Unicode string literals by letting you specify the Unicode encoding value of characters in the string. This is useful, for example, for
inserting data into NCHAR columns.
The Unicode encoding value has the form '\xxxx' where 'xxxx' is the hexadecimal value of a character in UCS-2 encoding format. To include the backslash in
the string itself, precede it with another backslash (\\).
For portability and data preservation, Oracle Corporation recommends that in the UNISTR string argument you specify only ASCII characters and the Unicode
encoding values.
Examples
The following example passes both ASCII characters and Unicode encoding values to the UNISTR function, which returns the string in the national character
set:
SELECT UNISTR('abc\00e5\00f1\00f6') FROM DUAL;
UNISTR
abceqv -
Insert french characters into the database
Hi,
My user requirement is to insert french characters into the db. However he has set as per my suggestion of altering session alter session set nls_language='french' he can't insert french characters. Is this using alter session helps to retrieve only the outputs in french language or to insert too?
Please help.
Version : oracle 8i
nls_parameters at database level:
SQL> select * from nls_database_parameters;
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET US7ASCII
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
PARAMETER VALUE
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZH:TZM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZH:TZM
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_NCHAR_CHARACTERSET US7ASCII
NLS_RDBMS_VERSION 8.1.7.0.0Your database character set is US7ASCII : you can only insert ASCII characters which is OK for most French characters but not all. This cannot work for:
àéèùçChanging NLS_LANGUAGE won't help. You need to change database character set to WE8MSWIN1252 for example. This should be easy in your case because US7ASCII is a binary subset of many others characters set. Please read http://docs.oracle.com/cd/A87860_01/doc/server.817/a76966/ch3.htm#47136 -
INSERTing chinese characters in SQL*plus
Db version: 10gR2
NLS_NCHAR_CHARACTERSET for my DB is AL16UTF16 by which i can store chinese characters. To INSERT using SQL*Plus, i tried to copy and paste some chinese characters from internet. When the characters get pasted, it becomes '?????' (question marks). What else do i have to set to store Chinese characters?
SQL> CREATE TABLE EMP2
2 (EMPNO NUMBER,
3 ENAME NVARCHAR2(500));
Table created.
SQL> Insert into emp2(empno,ename) values(889,UNISTR('????'));
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM EMP2;
EMPNO ENAME
889 ????Actually, it looks like Forums do something strange to URLs pasted into posts. Sorry!
The thread URL is Re: store/retrieve data in lang other than eng when CHARACTERSET is not UTF8 -
How can I write the chinese characters in a web with my magic mouse?
How can I write the chinese characters in the search box with my magic mouse?
You can do it with a trackpad but I am not sure about the mouse. Take a look at his link, http://support.apple.com/kb/HT4288
-
Retrieving Chinese Characters from SQL Server with JDBC
Im having problems correctly recieving Simplified Chinese from the database (SQL Server 2000).
Driver: sun.jdbc.odbc.JdbcOdbcDriver
It seems that I cannot force the Results Set's getString(String s) method to the correct character encoding UTF-16. Java claims to have 16-bit characters but the native windows encoding cp1242 (somehting like that) seems to not be working for me.
I can read it in from a unicode text file using the InputStreamReader object, and it will display correctly.
All I ask is this: Has anyone successfully retrieved information from a database and displayed it correctly in a Swing application?
Any help is welcomeThanks for the help.
I was suspecting there was a problem with the driver. Microsoft's Driver worked perfectly for SQL 2000, but my target database is SQL 7 and the driver is not reverse compatible.
I am looking for a Free liscenced JDBC driver that will work with SQL 7 (other than the sun.jdbc.odbc.JdbcOdbcDriver)
Nothing fancy needs to be supported, just scrollable result sets, and basic insert, update, select, exec commands.
Maybe you are looking for
-
How can I include a carriage return in a expression
How can I include a carriage return in a expression between text strings eg Expression 1 = Text1 & text2 & text3 & text4 I need to display it as below Text1 Text2 Text3 Text4 adjusting the box the size doesn't work as the text strings are variable le
-
"Allow this device to wake the computer" option resets
Hello All, I'm wondering if anyone has come across this. Everytime I disable the Power Management option "Allow this device to wake the computer" click OK, the setting stays, once I reboot the computer, the option is enabled again. I've checked the
-
What is maximum column name length?
What is the maximum column name length in Oracle (XE) ? Peter
-
My Airplay disappeared from my Windows laptop, using iTunes vs 12.1.1.4, but I still see it on my iphone6 and ipad. How do I get it back on my laptop?
-
Hi All, I learning to use JNET and have some queries here.Any help would be appreciated. 1)I am using the following layout defination for a node> <type name="pv.applicant"> <editprops type="Untouchable" />