Results 1 to 6 of 6
  1. #1
    harsimran05 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default 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());
                }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default 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().

  3. #3
    harsimran05 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default 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

  4. #4
    harsimran05 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default 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)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default Re: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incor

    Quote Originally Posted by harsimran05 View Post
    i make the change u tell nd i get error in the line that is in while loop
    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:
    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
    which you might have spotted if you had formatted your code correctly...

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

Similar Threads

  1. Replies: 3
    Last Post: 08-15-2011, 10:16 AM
  2. Replies: 2
    Last Post: 08-11-2011, 02:41 PM
  3. Replies: 1
    Last Post: 10-16-2008, 02:09 PM
  4. Replies: 1
    Last Post: 08-06-2007, 09:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •