Well What i meant is that instead of entering single rows in the table every time can we directly pass a arraylist from java which holds say 5 employee objects which correspond to employee records/rows in emp table in the database.
I understand that we can use prepared statement and then pass the objects one by one. But my question is how do we pass the entire array to database so all records gets inserted at once.
Joined: Oct 08, 2006
You can store Java objects serialized in a binary field of the database. But that's a bad practice and bad datamodel. You're going to tight couple Java with a RDBMS. I wouldn't recommend that.
Just create a chain table where in you insert every entity as a new row referenced with a foreign key to the parent entity -if any.
You should not design from Java to datamodel, but from datamodel to Java.
Joined: Aug 02, 2005
Yeah i know this way. Do you mean the one below right?
Use Case : Let us suppose that we have a java bean Employee and we are trying to send an array of employee records at a time to database.
Is this bad way though? I am asking this question as it was asked in one of the interviews. I googled and found this solution.