CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2000
    Posts
    1

    Servlets/JDBC: SQL Exception when updating table

    Hi,

    I'm getting an SQL Exception error when I doing something as simple as updating
    a table using JDBC with Servlets. Strangely, Option 2 seems to work with out any problems. I am wondering if there is some syntax related issue here.

    Option 1. (does not work)
    First I get the Parameters as below:
    String cn = request.getParameter("tCustomer_Name");
    String ln = request.getParameter("tLogonID");
    String pw = request.getParameter("tPassword");
    String sa = request.getParameter("tAddress");
    String cy = request.getParameter("tCity");
    String st = request.getParameter("tState");
    String zp = request.getParameter("tZip");

    Then I create a statement and execute it as follows:
    Statement stmt = con.createStatement();
    stmt.executeUpdate("INSERT INTO Customers VALUES (cn, ln, pw, sa, st,zp)");

    Option 2. (this works fine)
    stmt.executeUpdate("INSERT INTO Customers VALUES ('John Doe', 'JoeD', 'password', '1234 N W 2nd Street', 'TX', '55455')");

    Any clues as to what's going on here????
    Thanks in advance.





  2. #2
    Join Date
    Sep 2000
    Posts
    3

    Re: Servlets/JDBC: SQL Exception when updating table

    Hello

    When you do this:


    Statement stmt = con.createStatement();
    stmt.executeUpdate("INSERT INTO Customers VALUES (cn, ln, pw, sa, st,zp)");




    You are updating de table with the values "cn", "ln", "pw",.... You have to do this:


    Statement stmt = con.createStatement();
    stmt.executeUpdate("INSERT INTO Customers VALUES ('" + cn + "'," +"'" + ln + "'," +"'"+ pw + "'," + "'"+sa "' )");




    Enjoy JAVA.



Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured