Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Invalid Descriptor Index

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i keep on getting this error:
Problem: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
Its really wrecking my head and ive tried everything.Below is a copy of my code.Any suggestions?
Thanks
Dave

import java.io.*;
import java.sql.*;
//import oracle.jdbc.*;

public class dbTest
{
static Connection conn;
static String username, password;
static Statement stmt= null;

public static void main(String [] args)
{
conn = null;

try
{
//Load the jdbc-odbc bridge driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

username = "ca4photo";
password = "Tmppwd4db";
conn = DriverManager.getConnection("jdbc dbc:images",username,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, //Create a statement object so that we can submit
ResultSet.CONCUR_UPDATABLE); //SQL statements to the driver
//ResultSet rs = null;
String query = "SELECT idx FROM images where idx = 48046"; //SQL statement
ResultSet rs = stmt.executeQuery(query); //Execute SQL statement


while(rs.next())
{
String photo = rs.getString(1);
int ccount = rs.getMetaData().getColumnCount();
for( int i = 1; i <= ccount; i++ )
System.out.print(rs.getString(i)+"\t");
System.out.println();
}
System.out.println(rs.getString(3));

if(conn != null)
{
try
{
conn.close();
}
catch(Exception e)
{
System.out.println("Could'nt close connection \n"+e);
}
}
}
catch(Exception e)
{
System.out.println("Problem: "+e);
}
}

public Connection getConnection()
{
return conn;
}

}
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are trying to access columns of your result set that don't exist. That's what that error actually means.

I am not sure about your looping through the metadata part but this



Is certainly wrong. You only have one column in your result set.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic