lundi 26 janvier 2015

Query working in phpMyAdmin but not in Java [on hold]


CREATE TABLE IF NOT EXISTS


employee ( id int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(20) NOT NULL, designation varchar(200) NOT NULL, dob date NOT NULL, doj date NOT NULL, Salary bigint(20) NOT NULL, empId int(10) NOT NULL, PRIMARY KEY (id), KEY employee (empId) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;


Dumping data for table employee


INSERT INTO employee (id, name, designation, dob, doj, Salary, empId) VALUES (1, 'Firdose', 'seo', '1995-11-10', '2014-12-10', 10000, 1), (2, 'Firdoe', 'ceo', '1994-01-11', '2015-01-05', 10000, 2), (3, 'Firdose', 'ceo', '1995-01-11', '2015-01-05', 20125, 1), (4, 'Firdose', 'ceo', '1994-01-25', '2015-01-04', 20125, 2);


Table structure for table employer


CREATE TABLE IF NOT EXISTS employer ( id int(11) NOT NULL DEFAULT '0', name varchar(20) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Dumping data for table employer


INSERT INTO employer (id, name) VALUES (1, 'MCS'), (2, 'WIPRO');


ALTER TABLE employee ADD CONSTRAINT employee FOREIGN KEY (empid) REFERENCES employer (id) ON DELETE CASCADE ON UPDATE CASCADE


Now my question is I want to insert data in employee through java code .... I want to insert the last column as 'Wipro' but it should insert in table as '2' as it has foreign key constraint .... .... provide the query please ..... thanks in advance





Aucun commentaire:

Enregistrer un commentaire