应该不是你说的问题!!是其他问题引起的!!
你把源代码贴出来看看或者你先试试getObject("id")
然后再转成你想要的类型

解决方案 »

  1.   

    谢谢你看我的贴子,代码如下:
    <%
    try{
    String url=new String();
    String SQL=new String();

    url="jdbc:odbc:geography";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection(url,"sa","");


    SQL="select * from article";
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery(SQL);


    while(rs.next()){

    String count=new String(rs.getString("count"));//这个int类型的可以
    out.println(count);
    String id=new String(rs.getString("id"));//这个int(identity)类型的出错
    out.println(id);

    }
    rs.close();

    con.close();
    }
    catch(SQLException ex){
    while(ex!=null){
    out.println("SQLState:"+ex.getSQLState());
    out.println("Message:"+ex.getMessage());
    out.println("Vendor:"+ex.getErrorCode());
    ex=ex.getNextException();
    }}%>
      

  2.   

    你的数据库中有没有ID这个字段?
    如果有把:
    Statement stmt=con.createStatement();
    改为
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY);试试
      

  3.   

    这样吧。你看你的ID在geography表中是第几个字段,如果是第1个的话。
    用这个试试,
    String id=new String(rs.getString(1));
    是第2个的话就是:
    String id=new String(rs.getString(2));试试吧。
    怪了。
      

  4.   

    那就试试这个:<%
    try{
    String url=new String();
    String SQL=new String();

    url="jdbc:odbc:geography";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection(url,"sa","");


    SQL="select * from article";
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY); ResultSet rs=stmt.executeQuery(SQL); ResultSetMetaData rsmd = rs.getMetaData();
    int cols = rsmd.getColumnCount();
    for (int i=1;i<=cols;i++)
    out.print(rsmd.getColumnName(i)+"|");
    out.print("<br>");
    while(rs.next()){
    for (int i=1;i<=cols;i++)
    out.print(new String(rs.getObject(i))+"|") ;
    out.print("<br>");
    //String count=new String(rs.getString("count"));//这个int类型的可以
    //out.println(count);
    //String id=new String(rs.getString("id"));//这个int(identity)类型的出错
    //out.println(id);
    }
    rs.close();

    con.close();
    }
    catch(SQLException ex){
    while(ex!=null){
    out.println("SQLState:"+ex.getSQLState());
    out.println("Message:"+ex.getMessage());
    out.println("Vendor:"+ex.getErrorCode());
    ex=ex.getNextException();
    }}%>
      

  5.   

    非常感谢Andrawu和虚竹和尚,我的问题解决了。
    我将SQL="select * from article";
    改为:SQL="select count,id from article";就行了。
    看来取值是有顺序的。
      

  6.   

    对,这是个老问题了,从MS SQLServer中取数据必须要按照顺序,否则就会报“无效的描述符索引”错误。MS SQLServer is rubbish。