• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic