Why don't you just change the Character set for your tables?
Code:
ALTER TABLE <tablename> CHARACTER SET latin2 COLLATE latin2_general_ci;
Obviously you're going to get strange output (i.e. in UTF-8 format) unless you change the charset you're using.
My question to you is, why do you want it in UTF-8 if you're outputting in a different character set? Why don't you just use your original charset and collation? Is there any reasoning behind storing it as UTF-8 ?
Incidently you can use a select statement to set the output collation.
example :
Code:
SELECT _utf8'string' COLLATE utf8_general_ci FROM <tablename>;
Also, the statements you provide above:
Quote:
mysql_query("SET CHARACTER SET 'latin2'", $db);
mysql_query("SET NAMES 'latin2'", $db);
|
Are valid SQL for MySQL.
So i imagine there is no harm in doing an SQL query in Java that is "SET CHARACTER SET 'latin2'" and "SET NAMES 'latin2'" ...