Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8047055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:59:09+00:00 2026-06-05T05:59:09+00:00

I am trying to execute a prepared statment using the following: dbaBean.setPrepStmt(dbaBean.getConn().prepareStatement( SELECT id,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:59:12+00:00Added an answer on June 5, 2026 at 5:59 am

    I spent a few minutes trawling through the Postgresql JDBC driver source code, and it appears that what is happening is as follows:

    • When the prepared statement is created, the driver does a partial parse to split the SQL into statements, find placeholders and (I think) remove any comments.

    • The result of the parse is stored in the PreparedStatement object a sequence of fragments.

    • If you call toString() on the statement, the method reconstructs the SQL, inserting values for the placeholders, and adding a semicolon between each statement … if there are multiple statements.

    So, the disappearing semicolons are a feature, not a bug. Nothing in the JDBC specifications requires that the toString() method should give you the query in its original form … or in any form at all. And besides, it is normal practice using (at least for Postgresql) to leave off the trailing semicolon when writing SQL for JDBC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to execute the following lines only the last two statements are displayed(Here
I'm trying to execute the following line: exit | sqlplus username/password@sid @test.sql Works great
I'm trying to execute this: $ mysql --user=XXX --password=XXX --batch --skip-column-names \ -e SELECT
I am trying to execute DBCC CHECK DB('MyDB) using ADO.Net, but how can I
I am trying to insert and update data using 3 prepared statements. There are
I am trying to do prepared statements as follows: $stmt = $mysqli->prepare(SELECT COUNT(*) FROM
I am trying to build this prepared statement: $sql = SELECT * FROM entries
I'm using a prepared statement with this SQL code: SELECT `name` FROM `securities` WHERE
Just using a SELECT in my MySQL statement, trying to get a column. $last_visit
I'm trying to execute a query using a PreparedStatement in Java. I am getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.