Too few parameters error

hi,
i keep getting the following error:
SQLException in PAUserBean - getWorkNumber java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.here is code:
public String getWorkNumber(String Id) {
     String workNumber = "";
     try {
          Connection conn = DriverManager.getConnection("jdbc:odbc:PA");
          Statement s = conn.createStatement();
          String sql = "SELECT WORKER.WORK_PHONE_NBR FROM WORKER WHERE WORKER.USER_ID=" + Id + ";";
          ResultSet rs = s.executeQuery(sql);
          if(rs.next()) {
               workNumber = formatPhoneNumber(rs.getString("WORK_PHONE_NBR"));     
     }catch(SQLException e) {
          System.out.println("SQLException in PAUserBean - getWorkNumber " + e.toString());
     return workNumber;
}here is the database map:
WORKER TABLE:
USER_ID - Number (primary key)
WORK_PHONE_NMR - Text
I'm using an MS Access database, when i run the following query in MS Access it returns the number:
SELECT work_phone_nbr
FROM Worker
where id=102;
odd thing is the jsp page does display the number, meaning the query is ok, but i see tomcat's log with that error, any ideas what it means? what parameter am i missing?
Thank you.

Enclose the parameter with single quotes. Also, you don't need the semi-colon.
String sql = "SELECT WORKER.WORK_PHONE_NBR FROM WORKER WHERE WORKER.USER_ID='" + Id + "'";

Similar Messages

  • Java.sql.SQLException:[Microsoft][ODBC Driver]Too few parameters Expected 1

    Hi friends,
    Greetings.
    i am trying to work with my inventory management system. My code is as follows and i getan error as follows:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few
    parameters. Expected 1.
    CODING:
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class iteminsert extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    Connection con;
    Statement r,s;
    ResultSet rs;
    int flag1=0;//flag1 is for seeing if itemcode already exists
    String str1,str2;
    String s0=req.getParameter("itemcode");
    String s1=req.getParameter("itemname");
    int s2=Integer.parseInt(req.getParameter("unit"));
    int s3=Integer.parseInt(req.getParameter("minlevel"));
    int s4=Integer.parseInt(req.getParameter("rate"));
    int a=1;
    int b=0;
    res.setContentType("text/HTML");
    PrintWriter out=res.getWriter();
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:stocks");
    r=con.createStatement();
    s=con.createStatement();
    rs=r.executeQuery("select * from stock where itemcode='"+s0+"'");
    while(rs.next())
    flag1++;
    if(flag1!=0)
    out.println("<body><h1 align=\"center\"><font color=\"green\">INVENTORY MANAGEMENT SYSTEM</font></h1><p>ITEM CODE ALREADY EXISTS!!!!</p><p>To insert an item with a different code, <a href=\"http://localhost:8000/stock/insert.html\">Click here</a> .</p><p>To go back to the main menu <a href=\"http://localhost:8000/stock/index.html\">click here</a></p></body>");
    else
    str1="insert into stock values('"+s0+"','"+s1+"',"+s2+","+s3+","+s4+","+a+")";
    str2="insert into stock values('"+s0+"','"+s1+"',"+s2+","+s3+","+s4+","+b+")";
    if(s3<=s4)
    s.executeUpdate(str2);
    out.println("<body><h1 align=\"center\"><font color=\"green\">INVENTORY MANAGEMENT SYSTEM</font></h1><p>ITEM HAS BEEN INSERTED. HOWEVER REORDER LEVEL IS <b><u>MORE THAN</u></b> QUANTITY AT HAND</p><p>To buy more <a href=\"http://localhost:8000/stock/purchase.html\">Click here</a></p><p>To go back to the main menu <a href=\"http://localhost:8000/stock/index.html\">click here</a></p>");
    else
    s.executeUpdate(str1);
    out.println("<body><h1 align=\"center\"><font color=\"green\">INVENTORY MANAGEMENT SYSTEM</font></h1><p>ITEM HAS BEEN INSERTED.</p><p>To buy more <a href=\"http://localhost:8000/stock/purchase.html\">Click here</a></p><p>To go back to the main menu <a href=\"http://localhost:8000/stock/index.html\">click here</a></p></body>");
    con.close();
    catch(Exception e)
    out.println("error"+ e);
    Please help. I have to use only Create statement and not PreparedStatement :(
    Thank You.
    Regards.
    Aravind

    your code is wrong on so many levels.
    you should not be embedding HTML in Java objects this way. wrong, wrong, wrong.
    JSPs are what you should be using.
    look at this line:
    rs=r.executeQuery("select * from stock where itemcode='"s0"'");the SQL query is supposed to be a bloody string. yours won't even compile.
    do it this way:
    PreparedStatement ps = connection.prepareStatement("select * from stock where itemcode = ?");
    ps.setString(1, itemCode);
    rs = ps.executeQuery();you don't close resources. you don't use code tags.
    too much wrong to fix here.
    %

  • Pls help for Exception "Too Few Parameters : Expected 35"

    Hi,
    I am expericing with the exception
    "Too Few Parameters : Expected 35".
    What's wrong with it? The following is my code.
    try {                                                                                                                                                                                                                
    String DRIVER = ("sun.jdbc.odbc.JdbcOdbcDriver");               
    String URL = "jdbc:odbc:Industrial_One_DSN";
    String sql = "UPDATE BusinessRegistration " +
    "SET [Date] = ?, ISIC = ?, BizName = ?, BizAddress = ?, " +
    "OwnerName = ?, OwnerNRC = ?, Investment = ?, EstablishedYear = ?, " +
    "L_Male = ?, L_Female = ?, F_Male = ?, F_Female = ?, " +
    "OwnershipType = ?, Remarks = ?, IndustialZoneName = ?, Unit = ?, " +
    "Fuel = ?, FactoryType = ?, FactoryName = ?, Township = ? " +
    "MainProductName = ?, MainProductCountType = ?, " +
    "MainProductQuantity = ?, MainProductValue = ?, RMName = ?, " +
    "RMCountType = ?, RMQuantity = ?, RMValue = ?, EnergyName = ?, " +
    "MachinePower = ?, AmountGallon = ?, StateDiv = ?, BizSize = ?  " +
    "WHERE RegistrationID = ?";
    Class.forName(DRIVER);
    Connection con = DriverManager.getConnection(URL);
    PreparedStatement pstmt = con.prepareStatement(sql);
    int ilmale = Integer.parseInt(lmale);
    int ilfemale = Integer.parseInt(lfemale);
    int ifmale = Integer.parseInt(fmale);
    int iffemale = Integer.parseInt(ffemale);
    int impq = Integer.parseInt(mpq);
    int impv = Integer.parseInt(mpv);
    int irmq = Integer.parseInt(rmq);
    int irmv = Integer.parseInt(rmv);
    int iamountgallon = Integer.parseInt(amountgallon);
    pstmt.setString(1, date);
    pstmt.setString(2, isic);
    pstmt.setString(3, bizname);
    pstmt.setString(4, bizaddress);
    pstmt.setString(5, ownername);
    pstmt.setString(6, ownernrc);
    pstmt.setString(7, investment);
    pstmt.setString(8, eyear);
    pstmt.setInt(9, ilmale);
    pstmt.setInt(10, ilfemale);
    pstmt.setInt(11, ifmale);
    pstmt.setInt(12, iffemale);
    pstmt.setString(13, ownershiptype);
    pstmt.setString(14, remark);
    pstmt.setString(15, izn);
    pstmt.setString(16, unit);
    pstmt.setString(17, fuel);
    pstmt.setString(18, ft);
    pstmt.setString(19, fname);
    pstmt.setString(20, township);
    pstmt.setString(21, mpn);
    pstmt.setString(22, mpct);
    pstmt.setInt(23, impq);               
    pstmt.setInt(24, impv);
    pstmt.setString(25, rmname);
    pstmt.setString(26, rmct);
    pstmt.setInt(27, irmq);
    pstmt.setInt(28, irmv);
    pstmt.setString(29, ename);
    pstmt.setString(30, mpower);
    pstmt.setInt(31, iamountgallon);
    pstmt.setString(32, statediv);
    pstmt.setString(33, bizsize);
    pstmt.setInt(34, Integer.parseInt(rid));
    pstmt.executeUpdate();
    }I have got 35 fields in my db. But I wanna edit 34 fields only. I have no primary key in my table. Is't alright?
    pls help me.
    With thanks,
    WTDAHL

    I presume you are using SQL server, hence the [Date] in your SQL?
    I counted 34 question marks in your SQL statement, And 34 parameters supplied.
    Looks ok to me.
    You say you have no primary key? What is RegistrationId then?
    My suggestion for debugging: start smaller.
    Try updating it with only 5 fields, then 10 then 15 and build it up like that.
    Trying to debug 35 fields is a nightmare - you have to break it down to solve it.
    Good luck,
    evnafets

  • Too few parameters

    Hi friends,
    please solve this below problem. Exception is "-------Too few parameters"..
    import java.io.*;
    import Java.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import javax.sql.*;
    public class EmpData extends HttpServlet {
    public void service (HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
    try {
    PrintWriter out;
    out=response.getWriter();
    response.setContentType("text/plain");
    String a =request.getParameter("id");
    String b =request.getParameter("ename");
    String c =request.getParameter("esal");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:malloc");
    Statement stmt = con.createStatement();
    out.println(a);
    out.println(b);
    out.println(c);
    stmt.executeUpdate("insert into emp values (" + " ' " + a + " ' " + " , " + " ' " + b + " ' " + ", " + " ' " + c +" ' "+ ")" );
    }catch(Exception e) {
    System.out.println(e);
    }

    What's the actual value of that string? Don't just post a dog's breakfast of quotes that you put in your code to compute the string, post the string.
    And if you had posted this in the JDBC forum (being the question about your database queries that it is) you would have been told to use a PreparedStatement to avoid that awful mess of quotes. That would be a good idea in any case.
    When you look at the string you're probably going to find you are missing quotes around something that is supposed to be a string constant, and Access would try to interpret that as a table name or a column name. If there is no such table or column you get this sort of message.

  • Too few parameters. Expected 1.

    Im getting "Too few parameters. Expected 1." when trying to
    update a form, and I need a second pair of eyes if anyone can help?

    I found where the problem was located at, its the time and
    date column. I guess you could say its a ColdFusion bug. according
    to Adobe:
    quote:
    This is a known issue and Macromedia's Engineers are aware of
    it. Currently, the only known work around available is to avoid
    inserting and/or updating columns of "Date/Time" data types in
    Access with empty strings, ("") or with any other value that does
    not correspond to the range of values specified for the data type.
    when I took out "distribution_date='#FORM.dateOfdist#' which
    had a data type of Date/Time in Access it worked.
    more information about this topic
    can be found here
    Thanks

  • "Too Few Arguments" error when using Date Format

    I'm attempting to format some date information. I'm taking the following query:
    mysql_select_db($database_adventcms, $adventcms);
    $query_rsDatedetails = sprintf("SELECT * FROM tbEvents WHERE id = %s", GetSQLValueString($colname_rsDatedetails, "int"));
    $rsDatedetails = mysql_query($query_rsDatedetails, $adventcms) or die(mysql_error());
    $row_rsDatedetails = mysql_fetch_assoc($rsDatedetails);
    $totalRows_rsDatedetails = mysql_num_rows($rsDatedetails);
    and changing it to this:
    mysql_select_db($database_adventcms, $adventcms);
    $query_rsDatedetails = sprintf("SELECT *, DATE_FORMAT(datestart, '%b') AS whichMonth, DATE_FORMAT(datestart, '%Y') AS whichYear, DATE_FORMAT(datestart, '%D') AS whichDate FROM tbEvents WHERE id = %s", GetSQLValueString($colname_rsDatedetails, "int"));
    $rsDatedetails = mysql_query($query_rsDatedetails, $adventcms) or die(mysql_error());
    $row_rsDatedetails = mysql_fetch_assoc($rsDatedetails);
    $totalRows_rsDatedetails = mysql_num_rows($rsDatedetails);
    When I run it I get this error:
    Warning: sprintf() [function.sprintf]: Too few arguments in /home/iasindia/public_html/beta/newsandevents/eventdetails.php on line 60
    Query was empty
    which refers to the query line above. The odd thing is that same query works on a different query like this:
    $query_rsDates = "SELECT *, DATE_FORMAT(datestart, '%b') AS whichMonth, DATE_FORMAT(datestart, '%Y') AS whichYear, DATE_FORMAT(datestart, '%D') AS whichDate FROM tbEvents WHERE status = 'Live' AND datestart >= CURDATE() ORDER BY datestart DESC";
    $query_limit_rsDates = sprintf("%s LIMIT %d, %d", $query_rsDates, $startRow_rsDates, $maxRows_rsDates);
    $rsDates = mysql_query($query_limit_rsDates, $adventcms) or die(mysql_error());
    $row_rsDates = mysql_fetch_assoc($rsDates);
    But I can't get it to work on the $query_rsDatedetails above.
    Any help would be appreciated!

    The sprintf function is interpreting the date format type as an input. There are several solutions:
    http://stackoverflow.com/questions/5835534/mysql-query-date-format-and-sprintf

  • Too Many Parameters Errors. Toplink Generated Class error 300 columns table

    Hi Folks,
    I have a table which has around 300 columns, once I generate JPA entity using Entities from the Table wizard in Jdeveloper, it gives me an errror that too many parameters in the Method, that is actualy in the generated constructor.
    In case I delete half of the arguments in the constructor, it doest gives me error, as it doesnt exceeed the limit, would that be fine ? or Toplink internally need to call that constructor for the instrumenting purposes?
    Other option is to go by a default constructure, that I recommend personallly, but want to make sure it will work.
    Any comments, or anyone came into this problem before
    A.B
    Edited by: AAB on Sep 8, 2009 7:32 AM

    Hello,
    TopLink will only use the no argument constructor when building the object, then populate attributes using either attribute or property access. So the generated constructor taking arguments is not used at all by TopLinkl.
    Best Regards,
    Chris

  • Java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few...

    Can someone please help me? I get the error java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    The offending section of code is:
    int resultsTableID = 0;
    query = "SELECT results_table_01 FROM dbo_results_table_01 WHERE image_1_id = '" + file1ID + "' AND image_2_id = '" + file2ID + "'";
    System.out.println(query);
    rs = s.executeQuery(query);
    The select statement comes out:
    SELECT results_table_01 FROM dbo_results_table_01 WHERE image_1_id = '115' AND image_2_id = '116'
    There does not seem to be a problem with the parameter separations, so if anyone can spot what I have done wrong I would appreciate it.
    Thanks

    I have just tried what you advised: Not using single quotes, and I got the same error.
    The query now looks like:
    query = "SELECT results_table_01 FROM dbo_results_table_01 WHERE image_1_id = " + file1ID + " AND image_2_id = " + file2ID;
    Thanks for your help, but it did not work.

  • Sql exception :too few paprameters to update

    I am getting an sql exception in this query below.
    It says too few parameters :expected 1
    String query = "UPDATE INR SET " + month+ " = " + mnt+ " where (IT = '" + initial + "') AND (new = '" + later+ "' ) AND (number = '" + num + "' ) AND (code = '" + Id + "')";
    I am just passing 1 telling it to update month column with mnt .
    Thanks,

    Here is my code with JDBC connecting to an Access Table
    String data ="jdbc:odbc:MonthUpdateTable";
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     
         Connection conn = DriverManager.getConnection(data, "", "");
         Statement st = conn.createStatement();
         String query = "UPDATE INR SET " + month+ " = " + mnt+ " where (IT = '" + initial + "') AND (new1 = '" + later+ "' ) AND (number = '" + num + "' ) AND (code = '" + Id + "')";
         System.out.println(query);
         st.executeUpdate(query);
         st.close();
              conn.close();
    catch(Exception e) {System.out.println("UpdateError: " + e.toString()
               + e.getMessage());}
    Thanks,

  • Java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few pa

    I have 2 tables in my database as:
    db3
    Code | number primary key
    name | text
    priceperqty | number
    avail1 | number
    tempupdate
    transactedvalue | number
    Code | number foreign key
    I run following code:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection(
    "jdbc:odbc:inven");
    Statement stmt = con.createStatement(
    ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    stmt.setFetchSize(35);
    ResultSet rs1=stmt.executeQuery("Select avail1,transactedvalue from db3,tempupdate where db3.code=tempupdate.code");
    while(rs1.next())
    //subtracting available value - transacted value
    int a =rs1.getInt(1);
    int b =rs1.getInt(2);
    int c=b-a;
    int d=-(c);
    //storing results into an array
    for(int i=0;i<4;i++)
    y=d;
    i++;
    //printing on console
    System.out.println(""+a);
    System.out.println(""+b);
    System.out.println(""+d);
    //updating available values in table db3
    for(int i=0;i<4;i++)
    stmt.execute("update db3 set avail1="+y[i]+" where db3.Code=tempupdate.Code="+(i+1)+"");
    catch (Exception ex)
    ex.printStackTrace();
    Why does avail1 attribute does not show any updations and throws exception of too few parameters?can anyone help me?
    Edited by: Peter1 on Jul 2, 2008 4:39 AM

    zhaoyh wrote:
    tmt.execute("update db3 set avail1="y" where db3.Code=tempupdate.Code="+(i+1)+"");
    Changed it to PreparedStatement, and use ? for y. It should be
    stmt.execute("update db3 set avail1=? where Code="+(i+1)+"");
    If you're going to use PreparedStatement, it ought to be:
    PreparedStatement ps = connection.prepareStatement("update db3 set avail1=? where Code=?");
    ps.setInt(1, y);
    ps.setInt(2, i+1);
    ps.executeUpdate();

  • How to fix " Too few free dialogue work "  error.

    When i am trying to send idocs from one server to another, receipient server could not accept all the idocs generated in sender system and returning a error " Too few free dialogue work " . Kindly help to resolve the issue.

    This i had tried.. and set all the parameters using SRFC transaction, one thing i could not understand, the sender server is generationg just 500 idocs at a time, and receiver is not able to accept even 500 idocs, this small no of idocs.. while i many scenarios i have seen thousands of idocs are generated and they all are successfully received. while in my case, it always returns the error "Too few dialogue work processes. "

  • Error: can't fetch data for this host - too few bytes supplied by RPC

    Hi,
    In our internal Lab we have:
    One Admin, Media,Client Server (we can make backups for himself) - Solaris 10 with DDS4 tape drive (lab)
    One Windows Client (we can make backups) - Windows XP
    One Linux Client - CentOS 5.1
    When we add the linux client with the command:
    mkhost -a ob --inservice -r client -k 1024 linux
    We receive this message in the linux (host) /usr/tmp/observiced.log
    Error: can't fetch data for this host - too few bytes supplied by RPC partner (OB cached object manager)
    And in the obtool we receive (forever looping)
    Info: waiting for host to update certification status...
    Can you help us with this linux client error ? (iptables and selinux disabled!!)
    Thanks in Advance
    Serpins

    [SOLVED]
    Selinux not well removed....
    Thanks in Advance
    Serpins

  • Multisim 2001 "too many parameters for subcircuit" error

    When simulating circuits in Multisim 2001 with op amps from User library am getting Netlist Error message "Unable to correctly determine the nodes for the current circuit due to the following reasons:
            Too many parameters for subcircuit type lf156_op_amps_1 (instance: xxu3)"
    or a similar message for whatever op amp am using.  Have tried creating components for several different op amps and always get same error message.  Carefully checked the Pin Mapping Table and the symbol pins are correctly matched with order of pins in model.  The only way have been able to get a simulation to run with op amp components in the User Library is if copy an op amp directly from Multisim library to User library and make no changes whatsoever.  But if do something seemingly minor such as bring up the Symbol editor and add a text note underneath the symbol then get the "too many parameters for subcircuit" error.
    Am also getting a Consistency Self Check error stating "Error: The circuit it empty.  Simulation requires at least one ground."  Do have ground in circuit; presumably this error is related to Netlist error above.
    Operating system is Windows XP Professional.

    Well, this is an interesting situation in Multisim 2001. I tried doing this with another component and had the same results. I just renamed the part with no other changes and re-saved it to my database and sure enough I got this error. I have no idea what is causing this other than just a bug in the software. Us 2001 users will just have to live with this unless someone does happen to find a solution.
    I don't seem to have any problems when creating new components and using or editing existing symbols with new model information. This does suck. What if just wanted to edit one paramenter instead of using a completely different model? I really hope someone can find a workaround or solution to this. I am glad you broughtm this to our attention.
    Kittmaster's Component Database
    http://ni.kittmaster.com
    Have a Nice Day

  • Property list read error "stream had too few bytes"

    Hi
    I have created a plist but am having problems loading from it. The error message is "stream had too few bytes. The plist only contains a NSString at this stage. Herewith the code that I am ysing to try to extract the plist:
    testname = [NSPropertyListSerialization propertyListFromData:plistData
    mutabilityOption:NSPropertyListImmutable
    format:&format
    errorDescription:&error];
    Any help would be appreciated. Thanks.

    I have now noticed that although the list creation/update does not generate an error, no plist file is created in the specified path. I manually inserted a blank xml plist file and tried updating that, once again no error but it was not updated. It seems I am missing something in writing any kind of file to the NSBUNDLE MAINBUNDLE path?
    Any suggestions would be greatly appreciated.

  • Xcode Code signing error, try to resolve 'too few items in teams'

    HI ,
         I've been developing apps for a few weeks in Xcode 4, building and running without problems. Today when I try to build anything
         I get 'The identity 'iPhone developer' doesn't match any valid, non expected certificate/privilege key pair in your keychains  '
         The only solution i tried  was to go to the Xcode Organizer window/ Devices tab / Provisioning profiles . This displayed a blank
         page . I try 'Refresh' (icon in bottom right corner) and I get another message ' Too few items in teams' !
         (the only change i made today in Xcode is to try and connect to a svn repository...and failed )
         thanks in advance 

    @wanderingstan
    Did you solve this problem somehow?
    Thanks!

Maybe you are looking for