You are not logged in.

#1 2012-06-04 12:03:46

hypoglycemic
Member
Registered: 2010-01-14
Posts: 25

tomcat/postgresql dropping semicolon from query; causing it to fail.

I havea query funning from a bean though jdbc into postgres and somewher along the line the following query:

            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;"));

comes out as:
            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 = 'afrhadrgsdsdfdsgdfa' OR 'afrhadrgsdsdfdsgdfa' is null) ORDER BY date_created desc

You will notice the lack of semicolon at the end there.

What is the best way to work out where this is being dropped? I have tried to add a second semicolon but that is dropped also. Other queries in the same file seem to be operating fine and it is just this query that is the problem.

Offline

Board footer

Powered by FluxBB