I use the following code
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
String sql = "Select * from table";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++){
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
}catch(Exception e){
System.out.println(e);
}
It displays:
java.sql.SQLException:[Microsoft][ODBC Driver Manager] Invalid descriptor index
How is this caused and how can I solve it?
I have had the same exact error, this out of an ODBC Express Driver for Delphi.
The solution I have found is:
Place your varchar(max) and or varbinary(max) fields at the end of your select Query. (Order in the table definition doesn't matter).
This really fixed it for us, thought to share it with you guys.
I doubt the exception is thrown by one of the lines in the posted code. I have my reasons to state so.
A SQLException with the message "Invalid descriptor index" is usually obtained when you read the result set incorrectly. There are various ways in which this scenario can manifest:
If you need to solve it, you need to know which one of the above conditions is true in your code, and rectify accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With