Discussions

Web tier: servlets, JSP, Web frameworks: Invalid descriptors index

  1. Invalid descriptors index (3 messages)

    problem JSP code following:
    <%
    ... ...
    Statement stmt = connection.createStatement();
    ResultSet rs =
      stmt.executeQuery("select prod_id, weight from product");
    String prod_id = "";
    float weight = 0;
    while (rs.next()){
      product_code = rs.getString("product_code");
      weight = rs.getFloat("weight");
    }
    stmt.close();
    %>
    jsp run error show:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]invalid descriptors index
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataFloat(JdbcOdbc.java:3097)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataFloat(JdbcOdbcResultSet.java:5285)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getFloat(JdbcOdbcResultSet.java:648)
    ... ...
    But when i copied the problem code to a Java program, it run ok.
    I don't know why and hope to get your comments!
    Thanks

    Luke

    Threaded Messages (3)

  2. Invalid descriptors index[ Go to top ]

    Accidentally i found the reason.
    The order of getParameter must consistent with the select sentence.For example:

    strSql = "select prod_id, name from product";
    ... ...
    // OK
    String prod_id = rs.getParameter("prod_id");
    String name = rs.getParameter("name");

    // Wrong
    // error "invalid descriptor index" occur when running
    String name = rs.getParameter("name");
    String prod_id = rs.getParameter("prod_id");

    strange!!!

  3. Invalid descriptors index[ Go to top ]

    This happens when u r trying to access the columns in a different sequence ie. if the column name n the value u r getting is not matching.
    Ex:
    column names
    1:name 2:password 3:type
    While retrieving it strictly retrive in the same sequence.
     
    If u r using MS-Access it works but DBs like MS-SQL wont work.
     Hope this helps.
  4. Thanks[ Go to top ]

    Thank you for the solution. It really solved my problem that i have tried for two days. thanks again.