Forums Register Login

Inserting constant values but not form values on html form on web using tomcat

+Pie Number of slices to send: Send
Following is the piece of code which is working fine
and inserting values in ms access database when I give
values in quotes ( shown in code as commemted),but
when I try to insert form values it throws sqlexception.
Connection and PreparedStatement variables are defined
at class level as pst and c, and c.setAutoCommit(false)
is set at the begining of code.
When I display the sql with out.println(sql) it gives
correct insert statement with all form values but
not inserting.Please guide.
try {
sql = "insert into people " +
" values(" + request.getParameter("name") +
"," + request.getParameter("address") +
"," + request.getParameter("aqual") +
"," + request.getParameter("tqual") +
"," + request.getParameter("loc") + ")" ;
//" values('aaa','aaa','aaa','aaa','aaa')" ;

pst = c.prepareStatement(sql);
pst.executeUpdate();

c.commit();
c.setAutoCommit(true);
+Pie Number of slices to send: Send
use single quotes for Strings values.
Plz try with this code and let me know If you still face any problem.
sql = "insert into people " +
" values('" + request.getParameter("name") +
"','" + request.getParameter("address") +
"','" + request.getParameter("aqual") +
"','" + request.getParameter("tqual") +
"','" + request.getParameter("loc") + "')" ;
//" values('aaa','aaa','aaa','aaa','aaa')" ;

------------------
Amit Agrawal,
New Delhi, India.
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 873 times.
Similar Threads
Decimal precision and scale
How to update ?
Inserting into a table
how to retrieve value from autogenerated(oracle sequence) column in a servlet.
how to convert .csv files into sql server files using java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:16:44.