数据库的mysql
select * from map_t where placename='东四十条';
这条sql语句在程序代码中执行不能得出结果集(rst.next()返回false),而在命令行中执行完全正常,有一条结果.
而select * from map_t这句在程序中执行就能得到表中的所有数据,所以我发现只要sql语句中有中文,就不能正常执行,请问这是问什么?

解决方案 »

  1.   

    use PreparedStatement instead: Connection connection = <get connection>;
    String sql = "select * from map_t where placename=?"; PreparedStatement pst = connection.prepareStatement(sql);
    pst.setString(1, "东四十条"); pst.executeQuery();try again.
      

  2.   

    呵呵,谢谢你这个办法,可是还是不好使.
    我调用rst.next()返回false;
    可是我调用rst.isAfterLast()和rst.isLast()却也返回false,奇怪了.
      

  3.   

    你的数据库的编码是什么啊?如果是utf-8
    String s="东四十条";
    Connection connection = <get connection>;
    String sql = "select * from map_t where placename=?"; PreparedStatement pst = connection.prepareStatement(sql);
    pst.setBytes(1,s.getBytes() ); pst.executeQuery();
      

  4.   

    把数据库的编码改成 ANSI,就没问题了