characterEncoding has no effect in connection url
"Gu Lei(Tech)" <[email protected]> Fri, 10 Aug 2007 17:10:29 +0800
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <52211CB529416546A229E346F4E0BF4A02657800@Exchange-BE11.sohu-inc.com> |
Under Redhat as4 x86_64
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");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(conn != null)
conn.close();
} catch(SQLException e) {}
}
}
}
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?
非常感谢,祝您一切顺利
古雷
Network Operation Dept
Tel:62728824
Mobile: 13501384181
Email: [email protected]
msn: [email protected]
gtalk:[email protected]