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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:31:58+00:00 2026-06-05T16:31:58+00:00

I am developing an application in java for processing data and uploading it to

  • 0

I am developing an application in java for processing data and uploading it to a MySQL database. With this application, I iterate through all of the files that need processed in a directory. With each row of the file, I store the data from that row into a variety of variables and do some transformations to get all of the data ready for uploading to my database. Then I plan to upload that row’s data to the database with a PreparedStatement and INSERT query.

I am unfamiliar with the best practices for my situation. I’m in the process of teaching this to myself so I’m looking for a little guidance to make sure I do it correctly the first time.

Would it be inappropriate simply to open a connection at the beginning of the application’s runtime (ie. open it once)? For each insert query I would create and close the PreparedStatement, but I would simply leave the connection open until I finished processing all of the files.

I’ve read about connection pools elsewhere but I can’t figure out if it is applicable in my situation. I know its expensive to open and close connections frequently, but shouldn’t I be able to just open it once and run all of my queries under that connection?

If you would recommend using a connection pool, what service would you recommend for my situation. Preferably it will be easy to get a handle on quickly. My project is somewhat time sensitive. 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-05T16:32:00+00:00Added an answer on June 5, 2026 at 4:32 pm

    If you are developing a desktop Java application, you won’t be using connection pools. Connection pools are managed by Java Application Servers(Tomcat, JBoss, Glassfish) and will not be available in a desktop Java application.

    Keeping a connection open is plausible if you are going to be doing just one update.

    Also, a batch update would be a great idea for you:

    String connectionURL = "jdbc:mysql://localhost:3306/database";
    Connection con = null;
    PreparedStatement stmt = null;
    
    try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(connectionURL);
        stmt = con.prepareStatement(statement);
    
        for (Object o : list) {    // this is a list of your Java entity class
            stmt.setString(1, "foo");    // this is to update the parameters in the PreparedStatement
            stmt.setString(2, "bar");
    
             stmt.addBatch();     //  this adds the PreparedStatement to the batch of statements to execute
        }
    
        stmt.executeBatch();
    
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (stmt != null) {
            stmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
    

    The idea of a batch update is to have one prepared statement, where you can simply change the parameters, and add the “new” statement to a batch of statements. Then, you can execute them all at one go when you invoke stmt.executeBatch()

    I would advise you however, to execute statements probably 30 at a time if you have many such statements. Otherwise, you would be stranded if the program crashes/fails.

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

Sidebar

Related Questions

I'm developing a Java application that uses java.util.logging for its logging needs. This application
I am developing a java application for which I need only .xml files. Now
i'm developing a java application using the jstun library (hxxp://jstun.javawi.de/), and i need to
I'm developing a chat application in java using DatagramSocket and DatagramPacket . The data
I am developing a java application and I want to use: Reporting Analysis Data
I'm developing an application in JAVA SE, with a database in SQL Server. In
For an assignment I am developing an application that need to perform insertions in
I'm in the process of developing a multi-tiered financial processing application in Java using
I am developing a stand-alone java application which uses eclipselink. It is all fine
I am developing an application in Java, which manages a database of bank's loans.

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.