• 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

problem while inserting the record in db using mySQL

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am using mySQL DB.
I have written a servlet which gets the employee data from a JSP and then inserts that information in table.
I have created a database named employee_db.
My sql query is:
"Insert into employee values (name,id,join_date,designation)"
where name,id,join_date,designation these are parameters that i get from the request object.(consider i have successfully extracted the values.
The record is getting inserted properly.
but instead of actual values which the servlet got from the jsp it inserts NULL for all the column.
What can be the problem??
thanks a lot
trupti
Thanks a lot,
Trupti
[ December 17, 2002: Message edited by: trupti nigam ]
[ December 17, 2002: Message edited by: trupti nigam ]
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Syntax for an insert:
INSERT INTO table [(column [, column...])] VALUES ( value [,value...])
The syntax of an insert allows for only one table name, so you can't insert on a joined statement. You'll have to break it into one insert per table.
Jamie
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code snippet is given below:
String name = request.getParameter("employeeName");
String id = request.getParameter("employeeID");
String jDate = request.getParameter("employeeJoinDate");
Date join_date = dateInput.parse( jDate );
String designation = request.getParameter("employeeDesignation");
the query is:
String query = "Insert into employee (name,id,join_date,designation) values (name,id,join_date,designation)";
I am still facing the same problem.
I tried commit at the mySQL window but still the NULL values are getting inserted.
thanks,
Trupti
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is you are not using your variables...try this:

or better still:

hth,
-Pat
[ December 17, 2002: Message edited by: Pat Wallwork ]
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pat,
for the Date object we can insert it as Date object right?
Then the query will be:
String query = "Insert into employee (name,id,join_date,designation) values ("+name+","+id+",join_date,"+designation+")";
Am I right?
as for the above qyery also I am getting some syntax error.
Thanks a lot,
Trupti
[ December 17, 2002: Message edited by: trupti nigam ]
[ December 17, 2002: Message edited by: trupti nigam ]
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok atlast after 1/2 day's struggle I could find the error..:-)
thanks a lot to all who answered promptly to my query..
Trupti
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I seeing things, or did you original question have an insert on two joined tables?? Did you change the initial question after I posted??
I think I'm losing my mind!!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, maybe the problem is whit the primary key on your table; there is a primary key on the table that you want to insert a new record?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic