Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem while inserting the record in db using mySQL

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • 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: 627
  • Mark post as helpful
  • send pies
  • 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
 
Pat Wallwork
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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: 627
  • Mark post as helpful
  • send pies
  • 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: 627
  • Mark post as helpful
  • send pies
  • 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
  • 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!!
 
Manuel CR
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic