| Author |
Radiobuttons & comboxes in an SQL query
|
Donna Harrington
Ranch Hand
Joined: Aug 08, 2003
Posts: 31
|
|
Hey all, I have 3 radio buttons and i'm trying to insert the values of the radio buttons. I also have 3 combo boxes for date,month,year. In my database i have my radio buttons set to varchar and my combo boxes date,month,year are varchar also..but i dont know if this is the right way. I also don't know if my SQL statement is right. I'm getting this error when i compile program java.sql.SQLException: General error, message from server: "Column count doesn't match value count at row 1" Thanx <% String radio = request.getParameter("radiobutton"); String Username = request.getParameter("Username"); String Password = request.getParameter("Password"); String FirstName = request.getParameter("FirstName"); String Surname = request.getParameter("Surname"); String Address = request.getParameter("Address"); String City = request.getParameter("City"); String Email = request.getParameter("Email"); String telephoneNum = request.getParameter("TelephoneNum"); String radioB = request.getParameter("radiobutton"); String cardNum = request.getParameter("cardNum"); String date = request.getParameter("date"); String month = request.getParameter("month"); String year = request.getParameter("year"); String radioBtn = request.getParameter("radiobutton"); String shipName = request.getParameter("shipName"); String shipSurname = request.getParameter("shipSurname"); String shipAddress = request.getParameter("shipAddress"); String shipCity = request.getParameter("shipCity"); String shipCountry = request.getParameter("shipCountry"); String shipPostalCode = request.getParameter("shipPostalCode"); String driver="com.mysql.jdbc.Driver"; String connectionURL="jdbc:mysql://localhost:3306/petshopwebsite"; ResultSet rs = null; String password = ""; String username ="root"; //connection code PreparedStatement p = con.prepareStatement("INSERT INTO customerdetails(Title,Username,Password,FirstName,Surname,Address,City,Email,TelephoneNum,cardType, cardNum,date,month,year,shipTitle,shipSurname,shipAddress,shipCity,shipCountry,shipPostalCode)VALUES('" +radio+"','"+Username+"','"+Password+"','"+FirstName+"','"+Surname+"','"+Address+"','"+City+"','"+Email+ "','"+telephoneNum+"','"+radioB+"','"+cardNum+"','"+date+"','"+month+"','"+year+"','"+radioBtn+"','" +shipName+"','"+shipSurname+"','"+shipAddress+"','"+shipCity+"','"+shipCountry+"','"+shipPostalCode+"')"); int affectedRows= p.executeUpdate(); } [Edited by Jeanne to add linebreaks] [ May 31, 2004: Message edited by: Jeanne Boyarsky ]
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
Well - you KNOW your statement is incorrect when you get an error. 'Column count does not match' means 'Column count does not match' - it's always a good idea to read the errormessage and to interpret it. Here I found the suspicious columns - 3 and 4. It would be nice, if you edit your post (pencil-paper-icon), and insert some spaces in the very long rows, to give the program working in the background a chance to split them - thanks.
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
Since you are using a PreparedStatement (good) why are you in-lining the values (bad) rather than using the '?' placeholders and setting the data with resultSet.set methods?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Radiobuttons & comboxes in an SQL query
|
|
|