新的问题有出了
???
建表
create table gao
(
  id not null identity(1,1) primary key,
  name varchar(20),
  sex varchar(5),
  aa int,
  bb int
)
建视图
create view tt
as
(
   select [id],name,sex,aa,bb from gao 
)
建存储过程
create proc g
@p1 int,
@p2 int
as
  select [id],name,sex,aa,bb from tt where aa=@p1 and bb=@p2java调用它  并输出表中的数据
try
   {
    CallableStatement callst = null;
    Connection con = Jdbc.getConnection() ;
    callst = con.prepareCall("{call espshang(?,?)}") ;
    
    callst.setInt(1,1) ;
    callst.setInt(2,2) ;
    callst.execute() ;         
    ResultSet rs = callst.getResultSet() ; 
    while(rs.next())
    {
           System.out.println(rs.getInt("id")) ; ----看这里1
           System.out.println(rs.getString("name")) ;
           System.out.println(rs.getString("sex")) ;
    }
   }catch(Exception e)
   {
   e.printStackTrace() ;
   }
以上程序是正确的
  但我想这样输出,该如何??     while(rs.next())
    { 
           System.out.println(rs.getString("name")) ;----看这里1
           System.out.println(rs.getInt("id")) ;         
           System.out.println(rs.getString("sex")) ;
    } 位置可是变了呀!怎么就不对了??????

解决方案 »

  1.   

    也许跟ResultSet数据的排序有关系。
    顶一下!
      

  2.   

    Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
    at com.jdbc.Text.main(Text.java:42)
      

  3.   

    这可能和ResultSet类的设计有关,你可以看一下原代码
    如果你想改变显示顺序,那就用rs.getX*J()赋予相应的变量,在按照你想要的
    顺序输出就可以了
    例如:
    int id=rs.getInt("id");
    String name=rs.getString("name");
    String sex=rs.getString("sex");
    System.out.println(name);
    System.out.println(id) ;         
    System.out.println(sex) ;