Topic: 旧问重提(乱码),希望有高手解答,

  Print this page

1.旧问重提(乱码),希望有高手解答, Copy to clipboard
Posted by: snaileagle
Posted on: 2005-09-02 19:52

我用的是MySQL Server 5.0,在test 数据库下建了个student (name char(20))表,connect/j 是mysql-connector-java-3.2.0-alpha-bin.jar
用下面的程序测试,输出的结果出现乱码,希望各位能给点帮助
//test1.java
import java.sql.*;

public class test1 {
  static {
    try{
      Class.forName("com.mysql.jdbc.Driver");
      System.out.println("连接成功\n");
      }
      catch (Exception e){
        System.out.println("连接失败\n");
        e.printStackTrace();        
      }
  }
  public static void main(String[] a){
    try{
   Connection con=null;
     con=DriverManager.getConnection("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gb2312","root","snail");
      Statement state=con.createStatement();
      ResultSet result=state.executeQuery("SELECT * FROM student");
      System.out.println("姓名");
      while (result.next())
      {        
        String name=result.getString("name");
        System.out.println(name);
      }
      con.close();      
    }
     catch(SQLException e){
      e.printStackTrace();
    }
  }
}

运行结果:

连接成功

姓名
????
???ú

2.Re:旧问重提(乱码),希望有高手解答, [Re: snaileagle] Copy to clipboard
Posted by: pp_car
Posted on: 2005-10-30 14:22


http://www.cjsdn.net/post/view?bid=10&id=158877&sty=1&tpg=1&age=0


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923