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 9028829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:05:43+00:00 2026-06-16T07:05:43+00:00

Let’s say I get a PreparedStatement from a Connection object, and then later I

  • 0

Let’s say I get a PreparedStatement from a Connection object, and then later I overwrite the reference with another PreparedStatement. Then, later, I close() the reference. Will the first PreparedStatement (the one I lost the reference to) remain open? Or does some protocol or garbage collection take care of that?

For example:

PreparedStatement ps = connection.prepareStatement(MY_QUERY);
// do stuff
ps.execute();

ps = connection.prepareStatement(MY_OTHER_QUERY);
// do stuff
ps.execute();

ps.close();

Does the first PreparedStatement object, the one used to execute MY_QUERY, remain open?

  • 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-16T07:05:44+00:00Added an answer on June 16, 2026 at 7:05 am

    Yes, the PreparedStatement will be left open until it gets garbage collected* (if at all).

    That’s why you always see the rule to always release (close) external resources that you acquire.

    JDBC resources (such as this prepared statement, connections, results sets) and IO resources (sockets, streams, …) are the two most common resources that you manually need to manage in Java.

    * strictly speaking it could be closed in the finalize method which could be slightly before it gets GCed, but after it becomes eligible for the GC, but for this discussion this is close enough.

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

Sidebar

Related Questions

Let say I want to create an iOS app that download music files from
Let's say I have some text as follows: do this, do that, then this,
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say I wanted to remove vowels from HTML: <a href=foo>Hello there!</a>Hi! becomes <a
let's say I have selected the date 12/22/2012 then I go on and select
Let's say I want to write an FTP client from scratch. In the command
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say, I've got a XmlNode: <A>1</A> How to remove a text from it,
Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say I query for http://images.google.com.sg/images?q=sky&imgcolor=black and I get all the black color sky,

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.