Results 1 to 6 of 6
- 09-09-2011, 10:22 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
table tr has only 2 columns 1st is timeperiod of text type nd 2nd is rate also of text type nd my code is
Java Code: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=?"); ResultSet rs=ps.executeQuery(); ps.setString(1,tp); while(rs.next()){ tRate.setText(rs.getString(2)); } con.close(); } catch(Exception ex){ System.out.println(ex.toString()); }
- 09-09-2011, 11:59 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,467
- Rep Power
- 16
Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor
When you get an exception, post the full text of the exception and the stack trace, highlighting the line in your code where it happens.
In your case this will involve changing the catch block to include a call to printStackTrace().
- 09-09-2011, 12:34 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor
i make the change u tell nd i get error in the line that is in while loop
- 09-09-2011, 12:36 PM #4
Member
- Join Date
- Sep 2011
- Posts
- 6
- Rep Power
- 0
Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor
the stack trace is
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:31 48)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Jd bcOdbcPreparedStatement.java:215)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQue ry(JdbcOdbcPreparedStatement.java:90)
at FrmAdd.keyPressed(Prac1.java:380)
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)
- 09-09-2011, 12:39 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,467
- Rep Power
- 16
Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor
No you're not:
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStatement.java:90)
That is not the call to the ResultSet.getString() method.
It is failing because you are firing your query before setting your parameters:
which you might have spotted if you had formatted your code correctly...Java Code:PreparedStatement ps=con.prepareStatement("select Rate from tr where TimePeriod=?"); ResultSet rs=ps.executeQuery(); // Executing here ps.setString(1,tp); // But only setting the parameter here
- 09-11-2011, 05:13 AM #6
Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor
Similar Threads
-
Exception: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
By Mituff in forum Advanced JavaReplies: 3Last Post: 08-15-2011, 10:16 AM -
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
By nico in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-11-2011, 02:41 PM -
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]System Exception: Connection
By Ram_TPS in forum JDBCReplies: 1Last Post: 10-16-2008, 02:09 PM -
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
By leonard in forum JDBCReplies: 1Last Post: 08-06-2007, 09:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks