Java 正确。而且,我能看到它,所以终端也能正确显示字符。 CREATE DATABASE april DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; DROP TABLE IF E
Java 正确。而且,我能看到它,所以终端也能正确显示字符。 CREATE DATABASE april DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; DROP TABLE IF E,java,mysql,jdbc,utf-8,character-encoding,Java,Mysql,Jdbc,Utf 8,Character Encoding,正确。而且,我能看到它,所以终端也能正确显示字符。 CREATE DATABASE april DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; DROP TABLE IF EXISTS `article`; CREATE TABLE `article` ( `id` int(11) NOT NULL AUTO_INCREMENT, `text` longtext NOT NULL, `date_crea
正确。而且,我能看到它,所以终端也能正确显示字符。
CREATE DATABASE april
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
DROP TABLE IF EXISTS `article`;
CREATE TABLE `article` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` longtext NOT NULL,
`date_created` timestamp DEFAULT NOW(),
PRIMARY KEY (`id`)
) CHARACTER SET utf8;
OIL sands output at Nexen’s Long Lake project dropped in February.
ResultSet rs = st.executeQuery(QUERY);
long id = -1;
String text = null;
Timestamp date = null;
while (rs.next()) {
text = rs.getString("text");
LOGGER.debug("text=" text);
}
text=OIL sands output at Nexen’s Long Lake project dropped in February.
DriverManager.getConnection("jdbc:" + this.dbms + "://" + this.serverHost + ":" + this.serverPort + "/" + this.dbName + "?useUnicode&user=" + this.username + "&password=" + this.password);
characterEncoding=UTF-8
and
characterEncoding=utf8
rs.getBytes("text");
String[] encodings = new String[]{"US-ASCII", "ISO-8859-1", "UTF-8", "UTF-16BE", "UTF-16LE", "UTF-16", "Latin1"};
for (String encoding : encodings) {
text = new String(temp, encoding);
LOGGER.debug(encoding + ": " + text);
}
// Which outputted:
US-ASCII: OIL sands output at Nexen��������s Long Lake project dropped in February.
ISO-8859-1: OIL sands output at Nexenââ¬â¢s Long Lake project dropped in February.
UTF-8: OIL sands output at Nexen’s Long Lake project dropped in February.
UTF-16BE: 佉䰠獡湤猠潵瑰畴琠乥硥滃ꋢ芬ꉳ⁌潮朠䱡步⁰牯橥捴牯灰敤渠䙥扲畡特�
UTF-16LE: 䥏⁌慳摮畯灴瑵愠⁴敎數썮겂蓢玢䰠湯慌敫瀠潲敪瑣搠潲灰摥椠敆牢慵祲�
UTF-16: 佉䰠獡湤猠潵瑰畴琠乥硥滃ꋢ芬ꉳ⁌潮朠䱡步⁰牯橥捴牯灰敤渠䙥扲畡特�
Latin1: OIL sands output at Nexenââ¬â¢s Long Lake project dropped in February.
mysql -u april -p -D april < insert_articles.sql
INSERT INTO article (text) value ("OIL sands output at Nexen’s Long Lake project dropped in February.");
BufferedReader reader = new BufferedReader(new FileReader(new File("/home/path/to/file/sql_article_inserts.sql")));
String str;
while((str = reader.readLine()) != null) {
LOGGER.debug("LINE: " + str);
}
LINE: INSERT INTO article (text) value ("OIL sands output at Nexen’s Long Lake project dropped in February.");
SET names utf8
CREATE DATABASE mydb
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
UTF-8: OIL sands output at Nexen’s Long Lake project dropped in February.
//untested
for(char ch : text.toCharArray()) {
System.out.printf("%04x%n", (int) ch);
}
String test = "Test HEJ \u00C5\u00C4\u00D6 ÅÄÖ";
// here's how to define what character set to use when writing to a fileOutputStream
PrintWriter pw = new PrintWriter("test.txt","UTF8");
pw.println(test);
pw.flush();
pw.close();
System.out.println(test);