I am trying to execute a prepared statment using the following:
dbaBean.setPrepStmt(dbaBean.getConn().prepareStatement(
"SELECT id, author, title, url, article_text, date_created " +
"FROM articles WHERE " +
"(EXTRACT(YEAR FROM date_created) = ? OR ? is null) " +
"AND (EXTRACT(MONTH FROM date_created) = ? OR ? is null) " +
"AND (EXTRACT(DAY FROM date_created) = ? OR ? is null) AND " +
"(url = ? OR ? is null) " +
"ORDER BY date_created DESC;"));
dbaBean.getPrepStmt().setString(1, year);
dbaBean.getPrepStmt().setString(2, year);
dbaBean.getPrepStmt().setString(3, month);
dbaBean.getPrepStmt().setString(4, month);
dbaBean.getPrepStmt().setString(5, day);
dbaBean.getPrepStmt().setString(6, day);
dbaBean.getPrepStmt().setString(7, URL);
dbaBean.getPrepStmt().setString(8, URL);
System.out.println(dbaBean.getPrepStmt().toString());
dbaBean is an object that provides a connection and prepared statment. It doesn't do any manipulation at all.
I have used the above code for other methods quite successfully and have had no trouble with it at all. Now this function appears to be stripping the semicolon at the end, e.g. this is output with the System.out line:
SELECT id, author, title, url, article_text, date_created FROM articles WHERE (EXTRACT(YEAR FROM date_created) = NULL OR NULL is null) AND (EXTRACT(MONTH FROM date_created) = NULL OR NULL is null) AND (EXTRACT(DAY FROM date_created) = NULL OR NULL is null) AND (url = 'someurl' OR 'someurl' is null) ORDER BY date_created desc
Notice the missing semicolon.
I have tried adding a second semicolon and it too is 'eaten'.
Other changes are propogated fine (e.g. another field to select).
This is postgresql if that matters.
Edit: I care because I am having an error running this query and I thought the dropping of the semicolon was the potential culpret. The answers below seem to indicatate that this is not the case and I need to look elsewhere for it.