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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:10:40+00:00 2026-05-15T03:10:40+00:00

I have a Java-application that loads data from a legacy file format into an

  • 0

I have a Java-application that loads data from a legacy file format into an SQLite-Database using JDBC. If the database file specified does not exist, it is supposed to create a new one. Currently the schema for the database is hardcoded in the application. I would much rather have it in a separate file as an SQL-Script, but apparently there is no easy way to execute an SQL-Script though JDBC. Is there any other way or a pattern to achieve something like this?

  • 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-15T03:10:41+00:00Added an answer on May 15, 2026 at 3:10 am

    Your sentence “there is now easy way to execute an SQL-Script though JDBC” confused me for a minute, but I reckon you are saying “there is no easy way”. 🙂

    Based on what others have said, yes… the perfect world scenario is to use an ORM tool, like Hibernate, but I also understand the fact when you are dealing with legacy stuff at work, your team may not want to spend too much time refactoring that project.

    I agree that you should refactor out the database schema into a separate file. You can actually execute the SQL script using JDBC. I do that all the time when I run my certain testcases.

    Here’s how I do it. I use SQL Server database in my case. So, you need to tweak the code to fit your needs.

    String ddl = ... // load your SQL script file into this string
    String delimiter = "GO"; // in my case, SQL Server uses GO as delimiter, you use whatever you want here.
    
    
    private void executeDDL(String ddl, String delimiter) {
        Connection con = null;
    
        try {
            con = ... // get the connection
    
            // enable transaction
            con.setAutoCommit(false);
    
            Statement statement = con.createStatement();
    
            // for every DDL statement, execute it
            for (String sql : ddl.split(delimiter)) {
                if (StringUtils.isNotBlank(sql)) {
                    statement.executeUpdate(sql);
                }
            }
    
            statement.close();
            con.commit();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            try {
                con.close();
            }
            catch (Exception ignored) {
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that loads data from a .csv file and shows it
I have a rails app that loads lots of data from some java services.
I have a java application that people can log into (and do various things
I have a Java application that makes heavy use of a large file, to
I have a Java application that is managed using Maven. The project involves the
I have a standalone java application that fires up several JMS consumers using the
I have a few JAVA application that I monitor using JMX. I would like
I'm writing a small demo application in Java using Spring, that needs to have
I'm creating a Java EE application that's using JPA for data access. Initially I
I have a Java application that run as a background service, i.e. no GUI.

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.