furious_gamer
Excessive happiness
Hi friends,
I am developing an Web Application using JSP/Servlet and MySQL as backend.. I have a main table having 17fields. Out of 17, 4 were foreign key..(I hope u all know foreign key...A field linked from other tables primary key)...
In the first JSP form, user only wants to enter three forein key fields along with other datas and the fourth one left aside...
But it show me an error saying that foreign_key field cannot be "null".
I try to fix this by storing the string "NULL" in a variable(Like String temp="NULL") and in PreparedStatement, i give like this
ps.setString(1,temp);
instead of the previous one like
ps.setNull(1,21);//Here 21 is the equivalent for String
But now it shows a weird error like this
java.sql.SQLException: Duplicate key or integrity constraint violation, message
from server: "Cannot add or update a child row: a foreign key constraint fails
(`raj1/tbl_rmadetails`, CONSTRAINT `fk_raj1tbl_vendortbl` FOREIGN KEY (`VENDOR_I
D`) REFERENCES `tbl_vendor` (`vendor_id`) ON DELETE NO ACTION ON UPDATE NO ACTIO
N)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1741)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1588 )
at com.rajk.javacode.servlets.RMAEntryModel.addEntry(RMAEntryModel.java:
266)
at com.rajk.javacode.servlets.RMAEntryServlet.doPost(RMAEntryServlet.jav
a:51)
Now dudes, please tell me whats the possible cause for the problem....
Yeah, i knew that foreign key shouldnt left null, but my client doesnt want to enter that particular foreign key field....
And FYI i cant change that foreign key field to normal one as it collapses the project..
Help me friends....
I am developing an Web Application using JSP/Servlet and MySQL as backend.. I have a main table having 17fields. Out of 17, 4 were foreign key..(I hope u all know foreign key...A field linked from other tables primary key)...
In the first JSP form, user only wants to enter three forein key fields along with other datas and the fourth one left aside...
But it show me an error saying that foreign_key field cannot be "null".
I try to fix this by storing the string "NULL" in a variable(Like String temp="NULL") and in PreparedStatement, i give like this
ps.setString(1,temp);
instead of the previous one like
ps.setNull(1,21);//Here 21 is the equivalent for String
But now it shows a weird error like this
java.sql.SQLException: Duplicate key or integrity constraint violation, message
from server: "Cannot add or update a child row: a foreign key constraint fails
(`raj1/tbl_rmadetails`, CONSTRAINT `fk_raj1tbl_vendortbl` FOREIGN KEY (`VENDOR_I
D`) REFERENCES `tbl_vendor` (`vendor_id`) ON DELETE NO ACTION ON UPDATE NO ACTIO
N)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1741)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1588 )
at com.rajk.javacode.servlets.RMAEntryModel.addEntry(RMAEntryModel.java:
266)
at com.rajk.javacode.servlets.RMAEntryServlet.doPost(RMAEntryServlet.jav
a:51)
Now dudes, please tell me whats the possible cause for the problem....
Yeah, i knew that foreign key shouldnt left null, but my client doesnt want to enter that particular foreign key field....
And FYI i cant change that foreign key field to normal one as it collapses the project..
Help me friends....