Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor in

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor in

    table tr used has only 2 columns first one is time period of type text nd second is rate of type text
    acc. to me error is in bold lines
    my code is
    try  {	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access DRIVER (*.mdb);DBQ=trrelation.mdb");
     String tp=(String)mTimePd.getElementAt(cTimePd.getSelectedIndex());
    PreparedStatement ps=con.prepareStatement("select Rate from tr where TimePeriod=?");
     
    [B]ps.setString(1,tp);[/B]ResultSet  rs=ps.executeQuery();
    while(rs.next()){
        [B]tRate.setText(rs.getString(2));[/B]
     
     
    	}
    con.close();
                }
                catch(Exception ex){
                	ex.printStackTrace();
                }


    and the exception generated is
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor index
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLColAttributes(JdbcOdbc.j ava:2612)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getColAttribute(Jd bcOdbcResultSet.java:5443)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getColumnType(Jdbc OdbcResultSet.java:6054)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getMaxCharLen(Jdbc OdbcResultSet.java:5471)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbc ResultSet.java:277)
    at FrmAdd.keyPressed(Prac1.java:384)
    at java.awt.Component.processKeyEvent(Component.java: 6057)
    at javax.swing.JComponent.processKeyEvent(JComponent. java:2810)
    at java.awt.Component.processEvent(Component.java:587 6)
    at java.awt.Container.processEvent(Container.java:210 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4460)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2167)
    at java.awt.Component.dispatchEvent(Component.java:42 86)
    at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1879)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:742)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:1007)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:879)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:706)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4330)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2167)
    at java.awt.Window.dispatchEventImpl(Window.java:2554 )
    at java.awt.Component.dispatchEvent(Component.java:42 86)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 604)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descriptor index
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLColAttributes(JdbcOdbc.j ava:2612)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getColAttribute(Jd bcOdbcResultSet.java:5443)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getColumnType(Jdbc OdbcResultSet.java:6054)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getMaxCharLen(Jdbc OdbcResultSet.java:5471)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbc ResultSet.java:277)
    at FrmAdd.keyPressed(Prac1.java:384)
    at java.awt.Component.processKeyEvent(Component.java: 6057)
    at javax.swing.JComponent.processKeyEvent(JComponent. java:2810)
    at java.awt.Component.processEvent(Component.java:587 6)
    at java.awt.Container.processEvent(Container.java:210 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4460)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2167)
    at java.awt.Component.dispatchEvent(Component.java:42 86)
    at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1879)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:742)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:1007)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:879)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:706)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4330)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2167)
    at java.awt.Window.dispatchEventImpl(Window.java:2554 )
    at java.awt.Component.dispatchEvent(Component.java:42 86)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 604)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:138)

    Process completed.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid descripto

    rs.getString(2)

    To get the second value from the select statement, you need to select 2 or more in your statement. Right now, your PreparedStatement is selecting a single column.

Similar Threads

  1. Replies: 3
    Last Post: September 8th, 2011, 02:25 PM
  2. Problem With Applet Connecting With Microsoft Access Database
    By Saurabh Mittal in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 29th, 2011, 10:43 AM
  3. Microsoft Office Communicator through java
    By balaji in forum Java Theory & Questions
    Replies: 1
    Last Post: September 22nd, 2010, 01:36 PM
  4. Replies: 6
    Last Post: August 18th, 2010, 05:41 PM
  5. Replies: 6
    Last Post: August 30th, 2009, 04:31 AM