程序:
   public static void main(String[] args)
 {
  Connection connection = null;
  Statement statement;
  ResultSet resultSet;
 // 加载驱动程序以连接数据库
  try
  {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//这个驱动不能是其他的..
   connection = DriverManager.getConnection("jdbc:odbc:user","root","123456"); //user是data Source ,root是用户名,123456是进入mysql的密码
   System.out.println("open easy");
   String query = "Select * from userrole";
   statement = connection.createStatement();
   resultSet = statement.executeQuery( query );
   if(resultSet!=null){
       while(resultSet.next()){
           
          String s1=resultSet.getString(1);
          String s2 = new String(s1.getBytes("ISO-8859-1"),"GBK");
          System.out.println(s1+"..........."+s2);
          
       }
   }
   connection.close();
   System.out.println("close easy");  }
  // 捕获加载驱动程序异常
  catch ( ClassNotFoundException cnfex )
  {
   System.err.println(
   "装载 JDBC/ODBC 驱动程序失败。" );
   cnfex.printStackTrace();
   System.exit( 1 ); // terminate program
  }
 // 捕获连接数据库异常
  catch ( SQLException sqlex )
  {
   System.err.println( "无法连接数据库" );
   sqlex.printStackTrace();
   System.exit( 1 ); // terminate program
  }
  catch (Exception e)
  {
   System.out.println(e.toString());
  }
}//上面的程序引用自:http://blog.csdn.net/cctt_1/archive/2006/08/13/1057361.aspx运行后的结果:
open easy??...........????...........????...........??tommy...........tommyclose easy
----------------------------------------------------------------------
而Mysql表userrole中的数据为:mysql> select * from userrole;
+-------+
| name  |
+-------+
| 张三  |
| 李四  |
| 王五  |
| tommy |
+-------+
4 rows in set (0.00 sec)
表编码字符为:
mysql> show create table userrole;
+----------+---------------------------
-----------------------------+
| Table    | Create Table
                             |
+----------+---------------------------
-----------------------------+
| userrole | CREATE TABLE `userrole` (
  `name` varchar(20) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+----------+---------------------------
-----------------------------+
1 row in set (0.00 sec)
====================================================================请问:出现乱码??的原因是什么?应该怎么修改可以使读取的数据不为乱码?谢谢!