Welcome to hell. Yes, after hours of wrangling with MySQL and every

version of their JDBC drivers under the sun and poring over hundreds of
web pages, it appears that this is the "solution" to storing multibyte
characters in the database.

This means that *every single string* that might contain multibyte
characters has to be jiggered before being entered in the database and
unjiggered upon removal. And if we accidentally forget, things will appear
to be fine until we deploy to one of our multibyte foreign partners at
which point they'll see gibberish. Yay!

Too bad the Chinese didn't invent programming, then all this shit would
just work.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1417 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2004-04-26 02:43:35 +00:00
parent f3af4018c3
commit c091f63098
@@ -1,5 +1,5 @@
//
// $Id: JDBCUtil.java,v 1.5 2004/01/29 01:10:46 mdb Exp $
// $Id: JDBCUtil.java,v 1.6 2004/04/26 02:43:35 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -20,6 +20,7 @@
package com.samskivert.jdbc;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import com.samskivert.Log;
@@ -124,4 +125,37 @@ public class JDBCUtil
", modified=" + modified + "]");
}
}
/**
* Many databases simply fail to handle Unicode text properly and this
* routine provides a common workaround which is to represent a UTF-8
* string as an ISO-8895-1 string. If you don't need to use the
* database's collation routines, this allows you to do pretty much
* exactly what you want at the expense of having to jigger and
* dejigger every goddamned string that might contain multibyte
* characters every time you access the database. Three cheers for
* progress!
*/
public static String jigger (String text)
{
try {
return new String(text.getBytes("UTF8"), "8859_1");
} catch (UnsupportedEncodingException uee) {
Log.logStackTrace(uee);
return text;
}
}
/**
* Reverses {@link #jigger}.
*/
public static String unjigger (String text)
{
try {
return new String(text.getBytes("8859_1"), "UTF8");
} catch (UnsupportedEncodingException uee) {
Log.logStackTrace(uee);
return text;
}
}
}