在ResultSet rs=stmt.executeQuery(ls_2);后面要添一句
if(rs.next()){
   //什么也不做,只是起光标定位的作用
}  
你可以参考http://community.csdn.net/Expert/topic/3733/3733221.xml?temp=.8343622,跟你一样的情况!

解决方案 »

  1.   

    不是while(rs.next())这样你在ResultSet中的cursor已经移动到下一个了,所以你操作的结果和预想的不一样,应该这样:
    while(rs.hasNext()){
      //do something
      rs.next();
    }
      

  2.   


     wjsfr(令狐葱) :java.sql.ResultSet 有hasNext() 么???改正如下:
    protected void b1_actionPerformed(ActionEvent e){
       try{
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  String url="jdbc:odbc:People";
                  String user="sa";
                  String password="sa";
                  String ls_2="select * from BasicInfo where Name='张晶晶'";
                  Connection con=DriverManager.getConnection(url,user,password);
                  Statement stmt=con.createStatement();              if(rs.next()){//使用一下if//System.out.println("有数据");//打句话出来看看到底有没有结果,也许你根本没有查到数据,
    //原因是可能是数据库没有数据,也可能sql语句中汉字引起的编码问题                 
                  txt1.setText(rs.getString(1));
                  txt2.setText(rs.getString(2));
                  txt3.setText(rs.getString(3));
                  txt4.setText(rs.getString(4));
                  txt5.setText(rs.getString(5));
                                    
               }
               rs.close();
               stmt.close();
               con.close(); 
          }
           catch(SQLException sqle){
    //加上这个,除非你确信你很清楚发生这个异常的原因,
    //就最好把错误信息打出来,不要什么都不作,那样是很不方便你调试程序的,
    //看不到错误信息,也不方便别人帮你调试程序的
    sqle.printStackTrace();}
           catch(Exception exce){
    sqle.printStackTrace();
    }
     
          }
      

  3.   

    while(rs.next())应该没问题吧
    因为cursor开始是在第一条记录以前
    while(rs.next())能定位在第一条记录
      

  4.   

    同意pigo(少壮且行英雄梦,迟暮归守温柔乡) ( )的。
    楼主错在把指针定位到最后一条记录上了,所以得不到预期的结果。