Click to See Complete Forum and Search --> : Servlets/JDBC: SQL Exception when updating table


skan
September 14th, 2000, 09:46 PM
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.

Traider
September 15th, 2000, 08:11 AM
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.