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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:15:35+00:00 2026-06-10T13:15:35+00:00

The db tables that I am using are changing very often meaning new column

  • 0

The db tables that I am using are changing very often meaning new column can be add which will reflect my sql’s.

The solution that I was thinking is first “read” the meta data into some map and use it in order to retrieve the values something like this.

Read meta data:

public class Dynamic {
static public final Map<Integer, String> metadata = initMetaData();
HashMap<String, String> data = new HashMap<String, String>();

private static Map<Integer, String> initMetaData() {
    Map<Integer, String> tmpMap = new HashMap<Integer, String>();
    try {
        Connection connection = DBConnection.getConnection();
        try {
            Statement stmt = connection.createStatement();
            ResultSet result = stmt.executeQuery("SELECT * FROM TMP WHERE ROWNUM = 1");
            for (int i = 1; i <= result.getMetaData().getColumnCount(); i++) {
                tmpMap.put(new Integer(i), result.getMetaData().getColumnName(i));
            }
        } finally {
            connection.close();
        }
    } catch (SQLException ex) {
        …..
    }
    return Collections.unmodifiableMap(tmpMap);
}

public static String getColumnName(Integer index) {
    return metadata.get(index);
}

And when running the sql:

public static void test()        
    try {
        Connection connection = DBConnection.getConnection()
        try {
            Statement stmt = connection.createStatement();
            ResultSet result = stmt.executeQuery("SELECT * FROM TMP where idx = 'R5'");

            while (result.next()) {
            Dynamic d = new Dynamic()
                for (int i = 1; i <= Dynamic.metadata.size(); i++) {                        
                         d.setData(Dynamic.getColumnName(i),result.getString(Dynamic.getColumnName(i)));       
                }
            }

In this approach I have two problems(that I notice):

1) I need to execute two loops

2) I don’t know which get function to use via resultset since the type can also change.

How can I overcome those problems ?

I would also appreciate to get some other suggestion maybe there is a simple why

Thanks

  • 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-10T13:15:36+00:00Added an answer on June 10, 2026 at 1:15 pm

    1) What is your alternative to the inner loop? How would you get the field values? Do you think there is a lot of overhead in looping over small number of integers?
    2) You can get extra information about field data type from the same metadata where you get the field name and map the method names accordingly.
    3) You should really create a map for multiple tables – table/fieldSeq/fieldType/methodName and maybe few extra details – you don’t have to get them all dynamically all the time.

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

Sidebar

Related Questions

I am using the following InnoDB tables in mysql to describe records that can
Using SQL Server and T-SQL, how can I update ALL tables tables with a
Greetings, I have some mysql tables that are currently using an md5 hash as
I have a number of static classes that contain tables like this: using System;
I have a script that drops a load of tables using DROP TABLE IF
I'm using MySQL 4.1. Some tables have duplicates entries that go against the constraints.
I'm creating a map using Google Fusion Tables. It has several layers that are
How to fill multiple tables in a dataset. I m using a query that
I have a temporary table that I'm using and I have a unique column,
We are developing a service layer for a new system that will handle all

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.