Installing DDL with Java [duplicate] - java

This question already has answers here:
Java - Storing SQL statements in an external file [closed]
(12 answers)
Closed 9 years ago.
I need to install a DDL, preferably saved in a file, into a DB using JDBC. I have seen the addBatch() and executeBatch() methods in 'Statement' API but they seem to require adding individual statements one at a time. I am trying to find a way to add a big bulk of statements (DDL) that I can store in a file and pass as a paramter into a java app that will then use JDBC to install.

I'm going to give an answer that I think will help you maintainability wise, but it may not be what you're looking for. Here are two libraries that help with database migrations:
http://www.liquibase.org/
http://flywaydb.org/
Not only will these help you execute DDL in a file, they bring lots of other features you don't want to have to reinvent. EG, they'll make sure they only get run once if they succeed.
If these aren't the right tool for the job, I think the comment #Alpesh Gediya made is what you're looking for.

Related

Developing Java Swing Application that will use a database to store data and display it on the JFrame [duplicate]

This question already has answers here:
Java Embedded Databases Comparison [closed]
(18 answers)
Closed 6 years ago.
Good day, I have a potentially easy question. I am in the process of developing an application for my mother. She teaches a Sunday-school class, has been teaching it for many years now, and as you can guess, has a ton of information kept hard copy. She also has complex grading styles, a store where kids can buy stuff with their good grade points (called talents).
Anyway, I come from a background where I used a database to store massive amounts of information, but the database was always static. Meaning I would open MySQL, add an instance of our local DB, and then just connect to it whenever I need to. But the problem arises, how do I distribute an application that exists statically (ie you have to put all connection details into the program) be flexible enough to where I can install my App onto any computer and it would work without a specific database connection. In other words, is there a lightweight database that can be attached to a program that will be distributed?
I don't want to store information like Students in an array list, I am bent on using a database, unless someone can convince me. (also because with a database, it is easier to make the data persistent, it seems to me)
SO the question again, how do I develop an application that will use a database, but will also exist when you distribute the application to other computers without having a network database that has to be connected to every time the app is run?
I'm sorry if it is a basic question, I come from an HMI/SCADA background, things work a little differently...
You can use H2. It is a Java database.
http://www.h2database.com/html/main.html

Can batch programming use to read variables that inside .java and make change of it? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can I use batch programming to read java codes and identify the variables (inside .java or .class) and create a loop at batch programming and modify the variables?
For example
**Inside java**
String s = "abc";
Can batch programming read into java and retrieve the "String s" and modify using batch programming?
Thank you for your views, comments and answers.
Let me explain why am I asking this question.
I have a java code that able to pull files from FTP. There are many folders inside the FTP. And the java code able to pull files from each folder.One year got 52 weeks means that the FTP got 52 folders. I just want to pull files up to 3 weeks back but not 52 weeks. So I suggested them to create a simple function into java codes to pull files up to 3 weeks. But they said they prefer not to touch the java codes. Because they said in future there might be other vendor use this java codes to pull files.So they think that if create a batch file to solve this problem, in future they just need to change the setting in the batch files. They said "if I make changes in java,in future if there are 10 vendors, are you going to maintain 10 java codes?" So they request me to use batch programming to do it. =/. So I am asking is it possible to use batch programming to read variables and modify the variables and return to the java codes. If still unclear, please do ask me. I am willing to answer it.
My question is can I use batch programming to read java codes and identify the variables (inside .java or .class) and create a loop at batch programming and modify the variables?
In theory, yes.
In practice, it would be tricky (i.e. you would need to do some difficult Java programming to achieve it). And it is a BAD IDEA to modify the code like that, either at the source code or compiled code level. There are much simpler, safer and more transparent ways to implement the setting of configuration variables.
The normal way to handle variables that need to be changed for different runs of a program is to load the variables from a configuration file, or set them based on the command's command-line arguments, system properties or environment variables.
I will take note of this and let them know what situation I am in right now. Hope they will understand.
It is your job (as an IT professional) to convince them that they shouldn't ask for something really stupid ...

how to use predefined sqlite database [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use my own sqlite database?
Full Android Database Helper class for existing SQLite database?
I am new to android, i have created database using sqlite database browser now i want to use this database in my application so what are the step to do so any example code or any help will be appriciated
Follow the instructions from this blog
It will walk you through all the steps you need to use to get a pre-created db into your app.
EDIT
You didn't mention that your db was large in the initial post. In that case you might want to try android-sqlite-asset-helper
I don't see where it says it, but I know I've seen Mark from CommonsWare comment that it will transfer any size file for you. You zip up the db, put it in your assets/databases folder, and follow their directions to code your db class and you should be good to go.

How to test if a file is open in Java? [duplicate]

This question already has answers here:
Check if file is already open
(8 answers)
Closed 4 years ago.
Is it somehow possible to test if a java.io.File is currently open in another process by any process ? I am using Java 7 and target platforms are Linux/Windows/Mac.
There is no easy way in Java to go about this that will work reliably across different platforms. Depending on what you're trying to do, you might be able to patch together a series of try/catch statements which ostensibly work for most cases on most file systems, but you can never have full certainty that the next situation it encounters won't throw it off.
If you do end up going this route you want to ensure that when there is any doubt, it fails fast and doesn't get into a situation where it thinks a file is not open when it really is. My advice would be to see if there is any way you can possibly work around having to do this check.

How to use SQLite with GWT? [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
SQLite DB for GWT?
I know how to use SQLite with Android applications but I can't seem to figure out how to get started using SQLite with GWT for use in building a Packaged App for Chrome. What do I need? I've been searching for days and found nothing, so I think I'm off track. Any guidance would be greatly appreciated.
I'd check out gwt-jdbc-html5, since HTML5 now provides built-in SQLite support. There are plenty of other, heavier weight wrappers, but this is the best and easiest I've seen around.

Categories

Resources