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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:23:53+00:00 2026-05-24T00:23:53+00:00

In my Java code, I have something like this : ResultSet rs = statement.executeQuery(

  • 0

In my Java code, I have something like this :

ResultSet rs = statement.executeQuery(
                   "SELECT a,b,c FROM foo -- here starts the long query"+
                   " -- that is not yet finished " +
                   " -- that still has something to say... "+ 
                   " -- now the end !"
               );

I would like to clean up my code like this :

ResultSet rs = statement.executeQuery(all_queries.getQuery("The very long one"));

I have read that ResourceBundle is for localization. So I don’t think it matches in my case.

What should all_queries be ?

EDIT :
The most important thing for me is to clean up the code.

  • 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-05-24T00:23:54+00:00Added an answer on May 24, 2026 at 12:23 am

    I would put it in a file with an sql extension and implement Queries like:

    Queries {
        static public String getQuery(String name) {
            return loadResource("/com/example/queries/" + name + ".sql");
        }
    }
    

    User:

    conn.prepareStatement(Queries.getQuery("my_query"));
    

    Of course that’s only one way to do it. You can make Queries return Statement, or even use a dynamic proxy to mask it behind a simple Java interface (where proxy handler could create statement, set parameters and run query). Your mileage may vary.

    Added benefit: sql files have syntax coloring and are way easier to maintain than Strings in Java.

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

Sidebar

Related Questions

A java class does something like the following public class Foo { private final
In Java, I would do something like: Thread t = new MyThread(); t.start(); I
I'm writing code that runs on Google App Engine (Java). What I'm trying to
So basically, I have this content provider which I use to store and retrieve
I am trying to define a JQuery statement for finding elements which have a
i know virtually no java but i'm trying to learn some for this project.
we have here at work a very strange coding convention, and I didn't managed
I'm pretty new to Android but I have some experience (and a bit rusty
Hello fellow developer,i've getting problem to set the Timer method on ZK,default the method
I've got an activity that presents a listview of tracks of songs. When an

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.