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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:29:43+00:00 2026-05-20T05:29:43+00:00

I created a method that works Just Well Enough (takes ~4 seconds to complete)

  • 0

I created a method that works Just Well Enough (takes ~4 seconds to complete) on my computer. However, the end user will use the method in a remote-desktop environment, where the same request took anything from 25-50 seconds to complete. How can I optimize this program?

private void compareAndPopulateArrays(List<String> listOfGenIdsFromXml,
        List<String> listOfGenIdsFromDB, String dburl)
        throws ClassNotFoundException, SQLException {
    mdbAccessor = new MDBAccessor();
    for (int x = 0; x < listOfGenIdsFromXml.size(); x++) {
        Boolean matching_id_found = false;
        for (int y = 0; y < listOfGenIdsFromDB.size(); y++) {
            if (listOfGenIdsFromXml.get(x)
                    .equals(listOfGenIdsFromDB.get(y)) || equalsLanguageCodeIgnore(listOfGenIdsFromXml.get(x),listOfGenIdsFromDB.get(y))) {
                addNewMatchingRecognition(listOfGenIdsFromXml,
                        listOfGenIdsFromDB, dburl, x, y);
                matching_id_found = true;
            }
        }
        if (!(matching_id_found == true)) {
            newRecognitions.add(new NewRecognition(listOfGenIdsFromXml
                    .get(x)));
        }
    }
}
    private void addNewMatchingRecognition(List<String> listOfGenIdsFromXml,
        List<String> listOfGenIdsFromDB, String dburl, int x, int y)
        throws ClassNotFoundException, SQLException {
    String gen_id_Xml = listOfGenIdsFromXml.get(x);
    String gen_id_DB = listOfGenIdsFromDB.get(y);
    int issue_id = mdbAccessor.getIssueId(gen_id_DB, dburl);
    String issue_expression = mdbAccessor.getIssueExpression(gen_id_DB,
            dburl);
    String issue_detail = mdbAccessor.getIssueDetails(gen_id_DB, dburl);
    matchingRecognitions.add(new MatchingRecognition(gen_id_Xml, gen_id_DB,
            issue_id, issue_detail, issue_expression));
}

And all the mdbAccessor methods look similarly to the following:

public int getIssueId(String gen_id, String dburl) throws ClassNotFoundException,
        SQLException {
    Connection connection = setupConnection(dburl);
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement
            .executeQuery("SELECT issue_id FROM es_it WHERE gen_id='&&"
                    + gen_id + "' OR gen_id='&" + gen_id + "'");

    if (resultSet.next()){
        int getint = resultSet.getInt(1);
        resultSet.close();
        connection.close();
        return getint;
    }else{
        resultSet.close();
        connection.close();
        return -1;
    }
}

equalsLanguageCodeIgnore:

    public boolean equalsLanguageCodeIgnore(String gen_id, String gen_id_DB) {
    if (genIdsAreEqualMinusLanguageCode(gen_id, gen_id_DB)) {
        return true;
    } else {
        return false;
    }
}

private boolean genIdsAreEqualMinusLanguageCode(String gen_id,
        String gen_id_DB) {
    return gen_id_DB.contains("P-XX-")
            && gen_id.substring(5).equals(gen_id_DB.substring(5));
}

New and improved MDBAccessor class:

public class MDBAccessor {
private Connection connection;
private Statement statement;

public void setupConnection(String dburl)
        throws ClassNotFoundException, SQLException {
        connection = DriverManager
            .getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq="
                    + dburl);
        statement = connection.createStatement();
}

public void closeConnection() throws SQLException{
    connection.close();
}
////
public int getIssueId(String gen_id) throws ClassNotFoundException,
            SQLException {
        ResultSet resultSet = statement
                .executeQuery("SELECT issue_id FROM es_it WHERE gen_id='&&"
                        + gen_id + "' OR gen_id='&" + gen_id + "'");

        if (resultSet.next()){
            int getint = resultSet.getInt(1);
            resultSet.close();
            return getint;
        }else{
            resultSet.close();
            return -1;
        }
    }
  • 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-20T05:29:43+00:00Added an answer on May 20, 2026 at 5:29 am
    1. Get the items once, and pass the items around, instead of the lists and indexes. This will limit the number of lookups done in the Lists, which I expect are quite large. Depending on your version of Java you may want to use a for-each construct for readability.
    2. I expect you could consolidate the database accesses into a single query, which would save time.

      int issue_id = mdbAccessor.getIssueId(gen_id_DB, dburl);
      String issue_expression = mdbAccessor.getIssueExpression(gen_id_DB,
      dburl);
      String issue_detail = mdbAccessor.getIssueDetails(gen_id_DB, dburl);

    3. You seem to be opening and closing the DB for each query. Open it once, and close it at the end of the function, as the open and close of the DB connection is costly (especially against Access IIRC). You would likely want to make the connection object a member of your MDBAccessor class. Remember to use a try finally construct to ensure it is closed.


    Suggested refactoring for readability

    private void compareAndPopulateArrays(List<String> xmlGenIds,
            List<String> dbGenIds, String dbUrl)
            throws ClassNotFoundException, SQLException {
        //Better yet move it into an init method or the class constructor
        mdbAccessor = new MDBAccessor(dbUrl);
        for (String currXmlId : xmlGenIds) {
            Boolean matchingIdFound = false;
            for (String currDbId : dbGenIds) {
                if (currXmlId.equals(currDbId) || 
                        equalsLanguageCodeIgnore(currXmlId,currDbId)) {
                    addNewMatchingRecognition(currDbId, currXmlId);
                    matchingIdFound = true;
                }
            }
            if (!matchingIdFound) {
                newRecognitions.add(new NewRecognition(currDbId));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn about Expression trees, and I've created a method that takes
I've created a method that generates a new class and adds some methods into
I have created a console application that calls a method on a webservice. I
How can I create a method that has optional parameters in it in Visual
I have a method that creates a MessageDigest (a hash) from a file, and
I am attempting to build a simple method that creates an XML file from
I'd like to write a generic method that creates a new instances of a
Can I create a private instance method that can be called by a class
I have a method that's about ten lines of code. I want to create
I would like to create a safe sum extension method that would have the

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.