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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:18:46+00:00 2026-05-11T06:18:46+00:00

This question was suggested by Kyralessa in the What is your most useful sql

  • 0

This question was suggested by Kyralessa in the What is your most useful sql trick to avoid writing more sql?. I got so many good ideas to try from the last question, that I am interested to see what comes up with this question.

Once again, I am not keeping the reputation from this question. I am waiting 7 days, for answers, then marking it wiki. The reputation that the question has earned, goes into a bounty for the question.

Ground Rules:

  • While it is certainly reasonable to write code, to move processing from SQL into the code to address performance issues, that is really not the point of the question. The question is not limited to performance issues. The goal is less simply less sql to get the job done.

  • Communicate the concept, so that other users say ‘Oh Wow, I didn’t know you could do that.’

  • Example code is very useful, to help people that are primarily visual learners.

  • Explicitly state what Language you are using, and which dialect of SQL you are using.

  • Put yourself in your readers shoes. What would they need to see right there on the screen in front of them, that will cause an epiphany. Your answer is there to benefit the reader. Write it for them.

  • Offsite links are ok, if they appear after the example. Offsite links as a substitute for a real answer are not.

There are probably other things to make it nicer for the reader that I haven’t thought of. Get Creative. Share knowledge. Have fun showing off.

[EDIT] – It looks like there hasen’t been any activity in a while. 5 votes = 50, so there is the bounty, and it has been wikified.

  • 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. 2026-05-11T06:18:46+00:00Added an answer on May 11, 2026 at 6:18 am

    Where I work we’ve done several things to reduce SQL and to reduce the associated overhead of using SQL in Java. (We run Java with MSSQL, MySQL, and Oracle).

    The most useful trick is to use Java’s setObject method for binding parameters. This, combined with Varargs, lets you write a utility method for executing SQL:

    DBUtil.execSQL(Connection con, String sql, Object... params) 

    Simply iterate over the parameters and use statement.setObject(index, param[index-1]). For nulls you use setNull(). We’ve extended this concept for queries, with a getResultSet method; the wrapped ResultSet object also closes its statement, making it easier to do resource management.

    To reduce actual SQL code written, we have a query building framework that lets you specify a bunch of columns and their types, and then use this to automatically specify search criteria and output columns. We can easily specify joins and join criteria and this handles most of the normal cases. The advantage is that you can generate a report in about 10 lines of code, including different query parameters, sorting, grouping, etc. The code is too complex to include here.

    I’ve also used Oracle’s ALL_TABLES and ALL_TAB_COLUMNS tables to generate SELECT statements; another trick I’ve used is using the ResultSetMetadata to analyze the table:

    ResultSet rs = DBUtil.getResultSet(con, 'SELECT * FROM ' + someTable); ResultSetMetaData rsm = rs.getMetaData();  boolean first = true; for (int i = 1; i <= rsm.getColumnCount(); i++) {   String col = rsm.getColumnName(i).toUpperCase();   // do something with the column name } 

    This makes it easy to generate certain kinds of statements; in this case we have an active table and an archive table and we are moving records from one to the other. Without getting into a debate about using an archive table, the Java code I’ve written lets me modify the two tables without having to modify the archiving script.

    Another trick we use is to use constants for all our table and column names. This makes typing out SQL a little tedious but it allows us to (among other things) generate SQL easily for tables with similar or identical construction. Since we use constants to define the column names the code actually enforces that the the identical columns have the same name. Using constants also lets you find references to a particular column, thus allowing you to examine other SQL statements that may be related to the work you are doing. This lets us re-use SQL from other modules, instead of blindly re-writing the same statement again.

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According to the OpenJDK7 source code for javax.net.SocketFactory, the Sun… May 11, 2026 at 4:42 pm
  • Editorial Team
    Editorial Team added an answer There's just too little information here. For example, I am… May 11, 2026 at 4:42 pm
  • Editorial Team
    Editorial Team added an answer Not sure what display technology you are using (WPF or… May 11, 2026 at 4:42 pm

Related Questions

I often find myself implementing a class maintaining some kind of own status property
I have a C# module responsible for acquiring the list of network adapters that
EDIT: This was an old bug long since fixed in Scala 2.8 and later
I'm customize the fields displayed in the Pages document library (the table displayed clicking

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.