0
  1. what I want to do :

    input sql statement, and get the column name set . like this :

    select email as "邮件" from t_user

2.what I hava done:

    String url = "jdbc:mysql://127.0.0.1:3306/testcode?useUnicode=true&characterEncoding=utf8";
    Statement st = conn.createStatement();
    st.setFetchSize(1);
    ResultSet rs = st.executeQuery(sql);
    ResultSetMetaData rmd = rs.getMetaData();
    int columnCount = rmd.getColumnCount();
    for (int i = 1; i <= columnCount; i++) {
        String column = rmd.getColumnName(i);
    }
  1. what's problem I got: the column name is garbage characters(except english letters),but the resultset is ok.
JackyChen
  • 1
  • 1
  • 2
  • Where are you printing these column name? On the console, file, or web page? – Ravinder Reddy Dec 11 '13 at 06:24
  • @Ravinder 1. I debug it by eclipse , and the tips show that , and the workspace's charset is utf8. 2. exactly, the first time I found it is on the web page, then i debug it. 3. the source code i gave below, is a test project, i got the same problem. 4. I found something:the connection have a attr, characterSetMetadata, its value is CP1252. 5. Maybe the problem:<1>the datasource url setting.<2>the schema charset. – JackyChen Dec 11 '13 at 06:49
  • 1
    If it is in your Eclipse IDE, then you should look into [**this SO posting**](http://stackoverflow.com/questions/17742090/how-to-display-japanese-character-in-eclipse) ... – Ravinder Reddy Dec 11 '13 at 06:51
  • Please define garbage (or better yet: show the actual output) – Mark Rotteveel Dec 11 '13 at 07:42
  • @Ravinder I hava solved the problem. it's something wrong with the version of jdbc mysql-connector-java-5.0.jar, now i change it by 5.1. – JackyChen Dec 11 '13 at 08:10
  • exactly ,the old one is 5.0.5 . – JackyChen Dec 11 '13 at 08:20
  • the bugs : http://bugs.mysql.com/bug.php?id=27867 – JackyChen Dec 11 '13 at 08:48

0 Answers0