Results 1 to 4 of 4
  1. #1
    Mituff is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Thumbs down Exception: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

    Can some one help me find what is causing this Exception . All fields in the database table is Exactly as quoted below.
    Java Code:
    private void btnSearchKeyActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
            
            try {
                 String data = "jdbc:odbc:Stores";
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con = DriverManager.getConnection(data, "", "");
                 Statement sta = con.createStatement();
    
           
            String x=txtSearchKey.getText();
    
             // getting the data back
    
          ResultSet res = sta.executeQuery("SELECT * FROM Store WHERE SerialNum = "+ x +"  ");
          
          while (res.next())
                {
            String a = res.getString(1);
            String b = res.getString(2);
            String c = res.getString(3);
            String d = res.getString(4);
            String e= res.getString(5);
            String f = res.getString(6);
            String g = res.getString(7);
            String h = res.getString(8);
            String I = res.getString(9);
    
            txtSerialNum.setText(a );
            txtStoreNum.setText(b);
            txtNameOfItem.setText(c);
            txtQuantityRec.setText(d);
            txtQuantityIssue.setText(e);
            txtDateIssue.setText(f);
            txtDateRec.setText(g);
            txtStoreKeepersID.setText(h);
            txtSupplierID.setText(I);
    
         }
          res.close();
    
          sta.close();
          con.close();
        } catch (Exception e) {
          System.err.println("Exception: "+e.getMessage());
        }
    
        }
    After Using the printStackTrace this is the error below.

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java :3110)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcSt atement.java:338)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcO dbcStatement.java:253)
    at centralstoressystem.StoresInternalFrame.btnSearchK eyActionPerformed(StoresInternalFrame.java:472)
    at centralstoressystem.StoresInternalFrame.access$700 (StoresInternalFrame.java:21)
    at centralstoressystem.StoresInternalFrame$8.actionPe rformed(StoresInternalFrame.java:214)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:272)
    at java.awt.Component.processMouseEvent(Component.jav a:6288)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:605 3)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4651)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 81)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 81)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:643)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:602)
    at java.awt.EventQueue$1.run(EventQueue.java:600)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:616)
    at java.awt.EventQueue$2.run(EventQueue.java:614)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 613)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    Last edited by Mituff; 08-13-2011 at 07:31 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Show the full stack trace (use printStack Trace()) so we know exactly where it's thrown and all the exception info provided.

    Also, when posting code use code tags (the # button in the controls at the top of the reply box).
    You might want to print out the query before executing it as well, just to make sure it looks OK and will run in Access.

  3. #3
    Mituff is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    when i used stack trace this is result below.
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java :3110)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcSt atement.java:338)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcO dbcStatement.java:253)
    at centralstoressystem.StoresInternalFrame.btnSearchK eyActionPerformed(StoresInternalFrame.java:472)
    at centralstoressystem.StoresInternalFrame.access$700 (StoresInternalFrame.java:21)
    at centralstoressystem.StoresInternalFrame$8.actionPe rformed(StoresInternalFrame.java:214)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:272)
    at java.awt.Component.processMouseEvent(Component.jav a:6288)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:605 3)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4651)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 81)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 81)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:643)
    at java.awt.EventQueue.access$000(EventQueue.java:84)
    at java.awt.EventQueue$1.run(EventQueue.java:602)
    at java.awt.EventQueue$1.run(EventQueue.java:600)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:616)
    at java.awt.EventQueue$2.run(EventQueue.java:614)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 613)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    You don't think it might be an idea to point out what line this is?
    "at centralstoressystem.StoresInternalFrame.btnSearchK eyActionPerformed(StoresInternalFrame.java:472)"

    Also print out the query string (assuming it's the query execution causing the problem).

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2011, 03:41 PM
  2. Replies: 0
    Last Post: 02-16-2011, 02:30 PM
  3. Replies: 1
    Last Post: 10-16-2008, 03:09 PM
  4. Replies: 1
    Last Post: 08-06-2007, 10: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
  •