I am using sql server, my issue is when I change any stored procedure or database table changes I need to make track of it and need to update it on each and every server when my related java code is uploaded.
So I am finding something tool or something if possible with java code that if I give stored procedure or database changes file(i.e .sql file) it executes it on sql server.
May be my question is silly but I really want to know about is this possible with any tool or through code?
If I understand you correctly, the scenario would be:
Read .sql file using one of the Readers
Execute SQL commands using JDBC and Statement class.
Related
I am newbie in hsqldb.
In the project I am using Spring 4, Hibernate 5 and HSQLDB.
I am having some specific task and I am trying to use HSQLDB as a portable database, which can be transferred to a flash drive or another computer.
I already have an sql-script with all tables and basic-needed data.
I have four questions that are haunting me.
(I'm sorry in advance if these questions are very stupid):
I need to make the script run at the first launch of the program, and in the other launсhes it must to check if database already exist and (if it already exists)only update data in it. (the program would be used in many computers and the database must be created after the first launch).
How can I do this? Is it possible? Can you give some basic advice or example about how I can to do that?
I am trying to find some information about saving all database info in some file in the file-system. Can you give me please some valid examples about saving hsqldb data in file and about using this file after another launch.
Can I place this file in my project.jar file and to work with all data from it update it e.t.c. ?
What is the best practice to make my database portable(for specific tasks) and where should I keep it? In file, in my project jar.e.t.c.?
Thanks in advance for your answers!
For data storage, you use a file: database. The JDBC connection URL is in the form jdbc:hsqldb:file:<file path>. HSQLDB will save all the data to file.
After connecting to the database you execute the SQL statements in your script one by one. If the tables already exist, the CREATE TABLE statements throw an error. This shows you don't have to execute them.
Because it's up to you when to keep the existing data and when to update it based on the existing contents of the database, you execute some SQL statements to decide. There is no automatic way to do this.
You can put an HSQLDB database in a jar but it cannot be updated. Jars are read-only.
The databases are fully portable. You can place them in a subdirectory of the user's home directory with the ~ symbol. See http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_variables_url and the rest of this page for details.
I am developing a very small java application for people on my network. All it does is accept options for user input, grabs data from multiple SQLite databases (no updating to actual database!), and spits out a calculation. It works fine in eclipse but I cannot find a solution for running it as one consolidated application that I can distribute to my coworkers.
I am reading that JDBC is not able to query databases inside jars. I am also reading that it is dangerous and slow to keep the databases on the shared network. Finally, I am told I can create a temporary database when the program runs but I haven't a clue on how get the databases to copy into the temporary ones if the program cannot find them in the first place.
Here is the syntax I am using to access the databases:
Connection con = DriverManager.getConnection ("jdbc:sqlite:src/productLine.db", config.toProperties());
The database is located in the src folder. My questions are:
Is it possible (if advisable) to get the runnable jar to read a database inside of it?
Are there alternative options for this sort of problem?
Am I storing my databases properly or should they have their own source folder?
Is there a Java program to dump a table as a set of insert statements. I want to save state of a database table.
All I have is JDBC URL to DB which is located on network. Don't have Oracle installed thus no utilities and no SSH access either.
Looking for something similar to mysqldump or CSVWRITE in H2.
To save a state of a table you have several options:
Make a copy of the table data in another table.
Export using the oracle EXP or EXPDMP utilities.
Export into insert statements using external tools such as Toad,
SQLDeveloper (free from Oracle), PLSQL Developer. Or look for an online example and/or write your own.
It all depends on how you want to use the copy of your data and how much it is. For quick testing work a copy of the data in another table works best for me. With a simple sql script your table is back to it's original state.
I cannot understand how distributing Java programs that use a database works.
Let's say I am using Derby as RDBMS and I want to store tasks and calendar entries in a database.
I want each user of the program to have a local database.
But I don't understand how in-memory databases are supposed to work. Should I write a script so that the first time my program is launched it creates a database and empty tables? Or will they be already created during the installation of the program?
If your program wants to store the user's tasks and calendar entries in a database, you probably don't want to use an in-memory database, because the in-memory database disappears when your program exits.
Rather, you want to use an ordinary persistent Derby database, which will store the user's data in files in a folder on the filesystem.
You do indeed have to create the database and issue the CREATE TABLE etc. statements to create the tables in that database. You could provide that as a separate script, or you could have your program issue those statements itself.
Tables are not automatically created, though; you have to issue the CREATE TABLE statements one way or another.
I am want to export database table to a file.
I am using the following code, but it gives the following error.
String filename="D:/backup.txt";
I already create
st.executeQuery("select * from tamil into outfile'"+filename+"' fields terminated by ','");
But the error is:
java.sql.SQLException: Can't
create/write to file 'D:\backup.txt'
(Errcode: 13)
help me to clear the error
Thanks
But then you need to think how to put all this data into database.
You should consider mysqldump (or similar for other databases) http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Ever tried phpMyAdmin? You can easily manipulate your database with it.
Doesn't that error simply mean that you weren't allowed to write that file? Check if you can create a file with that name, in that location, for example using Notepad or by copying a file.
You need to remember that it will save it to the file on the computer that is running the database and NOT the computer running the java program. So for example, if the database computer is a Linux machine then
String filename="D:/backup.txt";
is definitely not going to work. So if you keep this in mind you can test why you cant write to D:/backup.txt.
The thing is, this error points to the fact your program is not able to access resources (files). Strange as it seems -you're in a windows environment-, you might check if the user which is executing your java app is allowed to create files in D:\
Also, as fazo stated, you'd consider using mysqldump, smart stuff which handles the whole process of setting data and schemas as well, into a file.