Hi
I am using MySQL 5, and created a table with Chinese column name like the following:
CREATE TABLE contacts ( 联系电话 varchar(20) , 客户姓名 varchar(50) , PRIMARY KEY(联系电话,客户姓名) ) ENGINE=InnoDB DEFAULT CHARSET=gbk ROW_FORMAT=REDUNDANT;
My jdbc code:
rs = stmt.executeQuery("select * from contacts"); ResultSetMetaData rsMetaData = rs.getMetaData(); int columnCount = rsMetaData.getColumnCount(); System.out.println("columnCount=" + columnCount); for(int i=1; i<=columnCount; i++) { System.out.print( rsMetaData.getColumnName(i)); System.out.println(); } while (rs.next()) { System.out.print(rs.getString("联系电话") + ", "); System.out.print(rs.getString("客户姓名") + ", "); System.out.println(); }
The result:
columnCount=2 è?”????”?è?? ?????·?§“??? java.sql.SQLException: Column '联系电话' not found. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:987) at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5584) at com.ictbox.acc.agenttoolbar.db.JdbcTest.main(JdbcTest.java:45)
I have set the default-character-set to gbk for the server, and add "useUnicode=true&characterEncoding=gbk" parameter in the connection string, but it didn't help Does JDBC support Chinese column name ? Is there any way to solve this.
|