To give a simple example of my problem:
//Create database table allowing nulls.
CREATE TABLE test(one int not null, two int null, three int not null);
Now, in Java I have an array of objects matching the database content. I need to create an insert/update/delete statement for this database table using the array values.
Object[] arr = { 4, null, 1 };
String sql = GenereateInsert(arr);
This gets difficult though because I need to leave out null fields from the insert in advance. E.g. if two above is not null:
INSERT INTO test(4, 2, 1);
everything is easy. But if it is null, I need the statement to be:
INSERT INTO test(one, three) values(4, 1);
The tables I'm dealing with are 50 columns and up, so I don't want to do this manually, it will be unmanageable. So, how do people address this problem in general? It must be a common situation.
PS: I don't want to use a full ORM library, that seems like overkill.