|
|||||||||||
|
characterEncoding has no effect in connection url
From: Gu Lei(Tech) <leigu(at)sohu-inc.com>
Date: Fri Aug 10 2007 - 05:10:29 EDT
This is my java program: import java.sql.*; public class JdbcExample3 { public static void main(String args[]) { Connection conn = null; try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://10.11.17.85/test?useUnicode=false&characterEncoding=utf8",
"test", "");
if(!conn.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
Statement s = conn.createStatement ();
s.executeQuery ("SELECT t FROM test");
ResultSet rs = s.getResultSet ();
int count = 0;
while (rs.next ())
{
String tVal = rs.getString ("t");
System.out.println (
" t = " + tVal
);
++count;
}
rs.close ();
s.close ();
System.out.println (count + " rows were retrieved");
} } } That program fetches some Chinese words from MySQL. When I changed characterEncoding=utf8 to characterEncoding=latin1 or any existed character set, the output won't change. It seems that characterEncoding= is no use in jdbc url. The output is dependent on environment variable LANG. When I change LANG, the output will also change. Driver is mysql-connector-java-5.0.7. MySQL Server's version is 5.0 and 5.1. Why characterEncoding in url has no effect? ·Ç³£¸Ðл£¬×£ÄúÒ»ÇÐ˳Àû
¹ÅÀ×
This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 10:14:14 EDT |
||||||||||
|
|||||||||||