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

  • SEARCH
  • Home
  • 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 8721375
In Process

The Archive Base Latest Questions

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

It this construction correct? Or are there any errors/bad habbits ? public static ResultSet

  • 0

It this construction correct? Or are there any errors/bad habbits ?

public static ResultSet getRecord(String id)
        {
            Connection conn = DataBase.Connect();

            try
            {
                try
                {
                    Statement stm = conn.createStatement();

                    ResultSet data = stm.executeQuery("SELECT * FROM " + GlobalFields.Records + " WHERE id = '" + id + "';");
                    return data;
                }
                finally
                {
                    conn.close();
                }

            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }

            return null;
        }
  • 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-13T07:12:43+00:00Added an answer on June 13, 2026 at 7:12 am
    1. You cannot process a resultset after you close the underlying statement or connection or both. If you intend to process it later, you should look at CachedRowSet that are built from the resultset and processed just like resultsets are, at a later point of time after closing the statement/connection.

    2. You are not properly closing the statement and result set. This is needed as closing Connection need not always mean closing the physical connection, particularly when you are using connection pools.

    3. The inner try block is unnecessary, you can as well push that finally block out, under the catch statement.

    Instead of handling connection, statement, resultset on your own, there are light-weight frameworks like Spring JdbcTemplate that would take care of closing resources properly.

    Also, if you are using JDK 7, then you should use the try-with-resources construct for all those closeable resources viz. connection, statement and resultset.

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

Sidebar

Related Questions

[a follow up to this question ] class A { public: A() {cout<<A Construction
I need this construction in my HAML code: - if something1 %div.a - elsif
I have browsed lift's MegaProtoUser and encountered this construction: ??(Last Name) . Can anyone
In Bash I can create a map (hashtable) with this common construction hput() {
In bash how can I make a construction like this to work: if (cp
Given this very familiar model of prototypal construction: function Rectangle(w,h) { this.width = w;
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
I am dealing with very primitive HTML construction that goes like this: <a NAME=header1></a><b><font
I saw the Velocity channel's Inside West Coast Customs this week featuring the construction
When I call: actor_ ! Exit How is this being converted into a construction

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.