Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / September 2004

Tip: Looking for answers? Try searching our database.

MySql ConnectorJ - how to insert Strings with mixed characterEncodings

Thread view: 
Barley - 16 Sep 2004 22:48 GMT
Say, for example, I want to run an insert like the following:

java.sql.Statement select = conn.createStatement();
select.executeUpdate("update test set observerNote='\u201C ... \u00BC'");

FWIW, u201C is an opening curly quote and u00BC is a fraction representing
one quarter.

If I create my JDBC url like this:

jdbc:mysql://localhost/test?user=test&password=test&useUnicode=true&characte
rEncoding=cp1250

then the curly quote is successfully inserted, but not the 'one quarter'
symbol. However, if I create the url in this way:

jdbc:mysql://localhost/test?user=test&password=test&useUnicode=true&characte
rEncoding=latin1

then the 'one quarter' is inserted but not the curly quotes. I understand
that the latin1 character set includes the 'one quarter' symbol, but not the
curly quote and that the cp1250 character set includes the curly quote but
not the 'one quarter' symbol, but I want a way where I don't have to choose
a single limited pool of characters.

How can I insert a String that contains both characters? Isn't there a way
to enable JDBC/MySql ConnectorJ to be able to insert Strings containing any
combination of Unicode characters?

Many thank to anyone who can clarify this issue.

Gregg
Mark Matthews - 17 Sep 2004 15:10 GMT
> Say, for example, I want to run an insert like the following:
>
[quoted text clipped - 26 lines]
>
> Many thank to anyone who can clarify this issue.

Gregg,

You'd need to use a characterEncoding of 'utf8', but you'll also need to
make sure that your tables can actually hold those values as well. You
don't say what version of MySQL you're using, but 4.1 is the version
where you can start 'mixing' character sets...MySQL-4.0 was basically
only one character-set per server and didn't understand utf-8.

    -Mark

Signature

Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

MySQL Guide to Lower TCO
http://www.mysql.com/it-resources/white-papers/tco.php

Barley - 17 Sep 2004 18:58 GMT
Thanks very much for your help, Mark, but I'm still missing something.

MySql version 4.1.4-gamma which I believe supports utf8.

My table is set to use the 'utf8' characterEncoding, and the
'utf_general_ci' collation (I have tried several other collations). My
connection url looks like:
jdbc:mysql://localhost/test?user=test&password=test&useUnicode=true&characte
rEncoding=utf8&characterSetResults=utf8

When I execute the same SQL I originally posted, gibberish characters are
inserted. The 'one quarter' symbol is in there, but so is a lot of other
noise.

What am I doing wrong? I know that my table can store these characters,
because I have pasted the String from Word into MySqlCC. Works just fine.

Thanks to anyone who can offer help.
Gregg

> > Say, for example, I want to run an insert like the following:
> >
[quoted text clipped - 5 lines]
> >
> > If I create my JDBC url like this:

jdbc:mysql://localhost/test?user=test&password=test&useUnicode=true&characte
> > rEncoding=cp1250
> >
> > then the curly quote is successfully inserted, but not the 'one quarter'
> > symbol. However, if I create the url in this way:

jdbc:mysql://localhost/test?user=test&password=test&useUnicode=true&characte
> > rEncoding=latin1
> >
[quoted text clipped - 19 lines]
>
> -Mark


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.