Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By RamyaSivakanth

Thread: JDBC Update exception-too few parameters. expected 6

  1. #1
    surbhijain93 is offline Member
    Join Date
    Nov 2013
    Posts
    5
    Rep Power
    0

    Default JDBC Update exception-too few parameters. expected 6

    so, first i search the id from table and all the fields are filled as in the screenshot. then i modify in the text boxes and click on button modify but exception comes-too few parameters. expected 6. pls help

    here is the code:

    try
    {
    JOptionPane.showMessageDialog(null,"Record succefully modified!\nID is "+id.getText()+" Password is "+lname.getText());
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("Jdbc:Odbc:Employe eDB");
    String str0=id.getText();
    String str1=fname.getText();
    String str2=lname.getText();
    String str3=address.getText();
    String str4=phoneno.getText();
    String str5=qualification.getText();
    String str6=designation.getText();
    String str7=dateofjoining.getText();
    String str8=salary.getText();
    int a=Integer.parseInt(str0);
    String use1="UPDATE employee SET E_Name="+str1+"',E_Address="+str3+",E_Phone="+str4 +",E_QUALIFICATION="+str5+",E_DESIGNATION="+str6+" ,E_JOINING_DATE="+str7+",E_SALARY="+str8+",E_PASSW ORD="+str2+" WHERE E_ID='"+str0+"'";
    Statement p11=con.createStatement();
    p11.executeUpdate(use1);

    }
    catch(Exception e){
    System.out.println(e);
    }
    Attached Thumbnails Attached Thumbnails JDBC Update exception-too few parameters. expected 6-screenshot.png  

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default Re: JDBC Update exception-too few parameters. expected 6

    first of all check ur query...the no of set values is lesser than your database fields and the way you are framing query is also not correct.
    Use StringBuffer/String Builder.
    best option is preparedstatement.
    As a startup ,just print your query in s.o.p and see whether are u missing ay database fields?????
    Tolls likes this.
    Ramya:cool:

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

    Default Re: JDBC Update exception-too few parameters. expected 6

    As Ramya says, the first step on a problem like this (and it should be an obvious step) is to simply print out the query.

    The second step is to use (as said) a PreparedStatement, so you don't have to think about quotes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,346
    Rep Power
    6

    Default Re: JDBC Update exception-too few parameters. expected 6

    Java Code:
    Connection con=DriverManager.getConnection("Jdbc:Odbc:EmployeeDB");
    I'm actually amazed that this apparently works. Or doesn't it perhaps?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

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

    Default Re: JDBC Update exception-too few parameters. expected 6

    Well, since it's getting to an exception when executing the query it would have to work.
    I'm more surprised that anyone is being asked to use the old driver anymore.
    Surely there can't still be tutorials out there using it?

    (Don't answer that!)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    surbhijain93 is offline Member
    Join Date
    Nov 2013
    Posts
    5
    Rep Power
    0

    Default Re: JDBC Update exception-too few parameters. expected 6

    Thank you everyone for your replies. Apologies for being stupid as I am very new to JDBC and it is being taught on my college currently.

    After typing sop this was the output:

    run:
    UPDATE employee SET E_Name=Ritu,E_Address=Faridabad,E_Phone=9818161064 ,E_QUALIFICATION=MCA,E_DESIGNATION=Administrator,E _JOINING_DATE=22-06-2011,E_SALARY=26000,E_PASSWORD=Jain WHERE E_ID=17
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 6.

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

    Default Re: JDBC Update exception-too few parameters. expected 6

    What happens when you try and execute that SQL directly in the database?

    Because it's not valid...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,076
    Rep Power
    4

    Default Re: JDBC Update exception-too few parameters. expected 6

    Lots of quotes are missing. Researching PreparedStatement would help you a lot. Like the two other people before me suggested.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Jprogressbar doesn't update as expected
    By Brad in forum New To Java
    Replies: 3
    Last Post: 11-13-2013, 01:17 AM
  2. Update doesn't work as expected?
    By RexBox in forum New To Java
    Replies: 3
    Last Post: 10-06-2012, 06:54 PM
  3. JDBC named parameters instead of ?, ?, ?
    By monkeynote in forum JDBC
    Replies: 5
    Last Post: 01-24-2012, 10:53 AM
  4. Error: Too few parameters. Expected 1.
    By mathidioticz in forum New To Java
    Replies: 5
    Last Post: 01-20-2012, 08:19 PM
  5. Replies: 3
    Last Post: 08-15-2011, 11:16 AM

Posting Permissions

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