Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help with UTF-8 characters into Oracle database

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with UTF-8 characters into Oracle database

    Hello all. I have an application written in jsp/java/oracle. My problem is on a table maintenance page that has a form containing a table with one row for each row of a table. It works perfectly for plain ASCII data. We introduced more users from Mexico that have characters in their name such as ń etc. The form also adds a row to the table dynamically and uses an ajax call to retrieve data from the active directory. The jsp page and the ajax jsp file both have the utf-8 character set defined and I can retrieve and display the new unicode data correctly. Unfortunately, when I click the save button, somewhere along the way the unicode characters do not stay intact. The form submit goes to the main servlet class and then is passed to the table maintenance class for processing. The columns in every row have the same name so I load the data into arrays to process each row using a similar line for each column: String[] names = req.getParameterValues("Name");. How can I load the name data into a table to preserve the unicode characters. I have read about byte arrays and Output streams, but they are beyond my current knowledge in java. Can anyone help me with what techniques I need to get the unicode characters into the database correctly? I have printed the values to the log file and and as soon as the data is loaded into the arrays, the characters are wrong. Any help will be greatly appreciated. I am a long time programmer but I have more or less taught myself java over the last year and a half.


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    50
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Help with UTF-8 characters into Oracle database

    There are two points you need to do:
    - Define the type of the column as NVARCHAR for unicode.
    - Append the N character before the string value in SQL statement, for example:

    UPDATE myTable SET myColumn = N'Some unicode text';

    The N prefix tells the DB that the text is unicode.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with UTF-8 characters into Oracle database

    This is not the problem. The database will accept the unicode characters. They are getting changed in the java code before the Insert is ever constructed. I write them to the log with System.out.println and the value is already mangled as soon as I enter the update class.

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Help with UTF-8 characters into Oracle database

    I know you can 'force' a character to be unicode by using \u.. Unicode Java

    However, to make an entire sentence.. you could probably use Normalizer, although I haven't personally used it before. Some links on it are below
    Normalizing Text (The Java™ Tutorials > Internationalization > Working with Text)
    Normalizer (Java Platform SE 6)

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with UTF-8 characters into Oracle database

    req.setCharacterEncoding("UTF-8"); fixed the problem in the maintenance module. If I add this to the main servlet class that receives all requests, can it break anything else? Will it have any impact on non unicode characters? I know this may seem like a strange question, but I am in unfamiliar territory here.

Similar Threads

  1. Java Barcode Program with Oracle database
    By techsing14 in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: December 6th, 2012, 05:19 AM
  2. jsp and oracle
    By sri latha in forum JDBC & Databases
    Replies: 0
    Last Post: March 10th, 2010, 09:29 AM
  3. Oracle and Sun
    By copeg in forum The Cafe
    Replies: 2
    Last Post: January 31st, 2010, 07:00 AM
  4. Database connectivity problem-Oracle
    By Entrant in forum JDBC & Databases
    Replies: 3
    Last Post: October 11th, 2009, 11:08 AM
  5. Oracle to Buy Sun
    By Fendaril in forum The Cafe
    Replies: 2
    Last Post: June 21st, 2009, 11:48 AM