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.