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?
Share
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.