aspose file tools*
The moose likes JDBC and the fly likes problem while inserting the record in db using mySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem while inserting the record in db using mySQL" Watch "problem while inserting the record in db using mySQL" New topic
Author

problem while inserting the record in db using mySQL

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jun 21, 2001
Posts: 613
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

Joined: Sep 23, 2001
Posts: 72
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

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jun 21, 2001
Posts: 613
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Dec 23, 2002
Posts: 3
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?
 
 
subject: problem while inserting the record in db using mySQL