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 4 of 4

Thread: Why the error said "few parameters expected 7" while i only have 6 fields?

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

    Post Why the error said "few parameters expected 7" while i only have 6 fields?

    Hye guys.

    Im newbie in java. I have developed a system in java. Firts function is, to enter all my customers details. Then when come to editing customer's details fucntion, i had problem. Let say i key in John, ID = 13184. Then i want to edit john's address by using editing function, so i need to enter john and ID in order to update the database. but i had problem to do that. The error said " there are few parameters".
    here is the code. can anyone help me with this?
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * editClient.java
     *
     * Created on Jul 18, 2011, 12:09:29 PM
     */
     
    package pos_system;
     
    /**
     *
     * @author dell
     */
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.Statement;
    import javax.swing.*;
     
    import java.sql.*;
    import java.sql.Statement;
    public class editClient extends javax.swing.JFrame {
        String id, name, add, tel1,tel2,tel3;
     
        /** Creates new form editClient */
        public editClient() {
            initComponents();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            jInternalFrame1 = new javax.swing.JInternalFrame();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            Ename = new javax.swing.JTextField();
            jLabel4 = new javax.swing.JLabel();
            EID = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            Eaddress = new javax.swing.JTextField();
            jLabel5 = new javax.swing.JLabel();
            EtelH = new javax.swing.JTextField();
            jLabel6 = new javax.swing.JLabel();
            EtelA = new javax.swing.JTextField();
            jLabel7 = new javax.swing.JLabel();
            EtelO = new javax.swing.JTextField();
            jButton2 = new javax.swing.JButton();
            jButton1 = new javax.swing.JButton();
            newSubmit = new javax.swing.JButton();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jInternalFrame1.setVisible(true);
     
            jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
            jLabel1.setText("Edit Client's Information");
     
            jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel2.setText("Name :");
     
            Ename.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnameActionPerformed(evt);
                }
            });
     
            jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel4.setText("ID :");
     
            EID.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EIDActionPerformed(evt);
                }
            });
     
            jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel3.setText("Address:");
     
            jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel5.setText("Tel No. (H):");
     
            jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel6.setText("Tel No. (A):");
     
            jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
            jLabel7.setText("Tel No. (O):");
     
            jButton2.setText("< BACK");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
            jButton1.setText("RESET");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            newSubmit.setFont(new java.awt.Font("Tahoma", 1, 12));
            newSubmit.setText("SUBMIT");
            newSubmit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    newSubmitActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(130, 130, 130)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3)
                                .addComponent(jLabel6)
                                .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(EID, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(Ename)
                                    .addComponent(Eaddress, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addGap(165, 165, 165)
                                        .addComponent(jButton1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(newSubmit)))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(EtelO, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(EtelA, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(EtelH, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(33, 33, 33)
                            .addComponent(jButton2)))
                    .addContainerGap(139, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1)
                    .addGap(46, 46, 46)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(Ename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(EID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addGap(50, 50, 50)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(EtelH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(Eaddress, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(EtelA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(EtelO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(newSubmit))
                    .addGap(68, 68, 68)
                    .addComponent(jButton2)
                    .addContainerGap(48, Short.MAX_VALUE))
            );
     
            javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
            jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
            jInternalFrame1Layout.setHorizontalGroup(
                jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            jInternalFrame1Layout.setVerticalGroup(
                jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jInternalFrame1)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jInternalFrame1)
            );
     
            pack();
        }// </editor-fold>                        
     
        private void EIDActionPerformed(java.awt.event.ActionEvent evt) {                                    
            // TODO add your handling code here:
    }                                   
     
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            client client2 = new client();
            client2.setVisible(true);
            this.setVisible(false);
     
            // TODO add your handling code here:
    }                                        
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            Ename.setText("");
            EID.setText("");
            Eaddress.setText("");
            EtelH.setText("");
            EtelA.setText("");
            EtelO.setText("");
            // TODO add your handling code here:
    }                                        
     
        private void newSubmitActionPerformed(java.awt.event.ActionEvent evt) {                                          
    i[B]d= EID.getText();
    name= Ename.getText();
    add = Eaddress.getText();
    tel1= EtelA.getText();
    tel2= EtelH.getText();
    tel3= EtelO.getText();
     
       try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con=DriverManager.getConnection("jdbc:odbc:POS1");
                Statement st =con.createStatement();
                ResultSet rs;
                PreparedStatement ins=con.prepareStatement("Update ClientInfo set Address=? ,ContactH=?, ContactA=?, Contact0=? where ID=? and Name=?");
                ins.setString(1, add);
                ins.setString(2, tel1);
                ins.setString(3, tel2);
                ins.setString(4, tel3);
                ins.setString(5, id);
                ins.setString(6, name);
                ins.executeUpdate();
                JOptionPane.showMessageDialog(this,"Data is successfully updated!");
            }catch(Exception e2) {
                JOptionPane.showMessageDialog(this,"Database test failure");
                System.out.println(e2);
            }
            // TODO add your handling code here:
        }                                         [/B]
     
        private void EnameActionPerformed(java.awt.event.ActionEvent evt) {                                      
            // TODO add your handling code here:
    }                                     
     
        /**
        * @param args the command line arguments
        */
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JTextField EID;
        private javax.swing.JTextField Eaddress;
        private javax.swing.JTextField Ename;
        private javax.swing.JTextField EtelA;
        private javax.swing.JTextField EtelH;
        private javax.swing.JTextField EtelO;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JInternalFrame jInternalFrame1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton newSubmit;
        // End of variables declaration                   
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: Why the error said "few parameters expected 7" while i only have 6 fields?

    That is way too much code to wade through, plus you forgot the highlight tags. You'd be better off if you boiled your problem down to an SSCCE- mostly, that's just a single method being called from main.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Why the error said "few parameters expected 7" while i only have 6 fields?

    Post the full error message, including the stack trace

  4. #4
    Member
    Join Date
    Aug 2011
    Posts
    48
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Why the error said "few parameters expected 7" while i only have 6 fields?

    Hi Hafiz,

    From your source code, I think you should check your SQL update statement which contains parameters in "?".

    The error "few parameters expected 7" is possibly that you have a SQL statement with 7 parameters but you fetch only 6.

    immutable objects
    Last edited by ha.minh.nam; December 4th, 2011 at 06:25 PM.

Similar Threads

  1. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  2. Syntax error on token ";", @ expected after this token
    By MagicMojo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2011, 07:48 AM
  3. Replies: 6
    Last Post: November 12th, 2010, 03:40 AM
  4. Replies: 1
    Last Post: March 31st, 2010, 09:42 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM

Tags for this Thread