I have to create a java application that can run entirely from a DVD. The application must connect with a database that will be also on the DVD. I was thinking to use an embedded database but i dont know much about them. Do i have to start the database server from my java application and if i do, how should i do it?
Thanks in advance.
Nick Tsilivis
You can use SQLite which is a very light weighted version of SQL. It stores its data in a single file. You even don't have to log in with an username and password. Just add this jar sqlite-jdbc to your projects build path. You cann access it by following:
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:your_database.db"); //"your_database.db" is the SQLite database file on your DVD.
/*manipulate your db by using PreparedStatement, ResultSet, ...
You must have installed SQLite on your system SQLite Download
That sounds like a job for SQLite. It runs completely in your own process, so there is no need to start an external database server.
Related
I have recently put all my java EE projects into my google drive so i can access them on my laptop and desktop computer. Some of my projects have a database component which I have the database stored in a MySQL server. Is there a way that I can export this database and just access it from like a database file which I can store in my project file so I can use it on both my laptop and desktop computer?
This is really what I would like:
-Be able to work on my java EE projects that have a database on both my computers
-Store my MySQL Server databases in a file which can go in my project folder then use java to access that database instead of going through the server
Any alternate ways of doing this would help me out this is just one way I can think of doing.
Note: I am using my laptop on the go so my desktop computer wont always be accessible from my laptop neither will I have an active internet connection always.
Thanks
Install MySQL on your laptop, then transfer database using backup/restore, e.g. using mysqldump. See https://dev.mysql.com/doc/refman/5.0/en/backup-and-recovery.html
This post is the continue of my previous question in here. So I had a look into how mySQL works with Java, but I noticed that the computer must have a database server to connect to the application. So what will happen when my software is ready and users want to run in a different computers? Can't I save the database file in the directory of the software, so any copy of the program will be connected to its independent database to save and parse data from it?
Just to make it clear, in a part of my software, I needs to keep record of previous interactions. Like a history table.
Would using JSON a better option in this case?
In a real world generally database servers are installed on a machine and softwares are installed on different machine.
We let software know the database configuration like database URL /database Name /username/Passwords etc (through property file or through JNDI configurationS).Then java program can connect to database with the help of JDBC driver.
Note:- one Database Server can Host many databases.
If you want to distribute your software without having dependency on client database. Then I would recommend you to use some inmemory DB.This DB you can embed with your software.(alternatively you can write logic that if client database can't be found then use inMemory DB..something like this).
H2 db is my favorite one and it also supports persistent mode and it support s many DB dialects including MYSQL .
I'm new in working with databases and connecting java to sql server. I just created a database and a java application for it. I used the sqljdbc4.jar file in my library and all the stuff required to connect the app with the database, but I want to know : what do I need to export so someone in an other computer can use that application and have that database in that computer, without having installed sql server or something, what do I need to do ?
It depends on what you want to do. If you want them to connect to a databse via your app, then you will have to allow them to access the database via your application by providing the privileges. If you want to bundle the whole database with your java code, then you need to use an in application database like h2 http://www.h2database.com/html/main.html. There are alternatives like derby and hsql db, but h2 is better than that. See the comparison on the h2 homepage.
I was wondering if it was possible to get an SQLITE manager database onto a server? What i mean by this is so that when i complete my program in a java project and make an installer for that project. Anyone who downloads it from any computer running on any operating system who has administration rights can access the database without having connection issues. In addition anyone who logs in to the program can do so with full database connection.
Is there a way to do this? I also don't want the user who is going to install the program to install any additional programs for the database. In addition i would like this program to work on any computer who might not have the SQLITEManager plugin on there firefox web browser or even have firefox installed on there computer.
I would also like the admin to be able to edit anything on the online server the database should be on.
If this is not possible on SQLITE Manager could you recommend a database which can do this but also use and work on the code already made for the sqlite programs?
SQLite databases are just flat-files. What this means in layman's terms:
I download your database as a file.
I can modify it as I please.
I'm not forced to synchronize to the newer version of the flat-file.
You have a choice: You either write your code to force periodic synchronization of the SQLite flat-file to your clients, or you use a dedicated DBMS on your server, such as MySQL, and force your clients to connect to that.
I developed an application with a java db database .I cannot access the database records when I close the netbeans IDE with the message "Error connecting to server Localhost on port..." My connection code to the Database is :
String host="jdbc:derby://localhost:1527/Employee;create=true";
String user="admin";
String pass="admin";
con=DriverManager.getConnection(host,user,pass);
How do I fix the problem?
Netbeans automatically starts the Derby server; you can see that in the "Services" tab (Ctrl-5).
You'll have to start the database server by hand if you don't use Netbeans; see the doc.
Presumably your Derby database is hosted in NetBeans? You'll need to create a standalone database.
You would have to probably start your database before connecting (you are using server mode). Have a look into Vogella tutorial on Derby db connection from java application: http://www.vogella.de/articles/ApacheDerby/article.html
I guess NetBeans has an embedded DB instance.
Try to use
jdbc:derby:/MyFolder/MyDatabase/Employee;create=true
or
jdbc:derby:C:\MyFolder\MyDatabase\Employee;create=true
if you do not need to access the DB from multiple applications.
You can use JavaDB (aka Derby) either by connecting to a JavaDB Network Server or by using it as an embedded DB when your application opens the DB files itself.
Currently, your application is connecting to a Network Server started by NetBeans, as your URL is telling to connect to port 1527 on localhost, i.e. your system.
What you need to do is tell your application to use JavaDB as an embedded database, i.e. it should manage the database itself instead of getting Netbeans to do it instead. You can do this just be changing the URL to something like:
jdbc:derby:Employee;create=true
You may need to tweak that URL depending on where the database files are stored relative to your application's working directory.
Only one application can have the DB open at one time. So when you're doing this NetBeans won't be able to open the database, and if NetBeans has the database open your application won't be able to open it. So you may find you want to reconfigure NetBeans as a DB client.
the simplest way of dealing with these problems is creating batch files..
first of all build your java database program.. the tricky part is to start the server. the jderby is a server so it needs to be started.. that's why you start the server in netbeans. so download db derby files from "http://db.apache.org/derby/releases/release-10.8.2.2.html". after you download these files, copy your netbeans project in those db jderby files.. go and copy your database folders from where they will be saved.. and paste them in the db jderby files.. now open notepad and type
#echo
start (PATH)
start (PATH)
the first path take the path of the file named start network server.bat
the second path take the path of the jar file of your main project.
Now save your the notepad as setup.bat and run the batch file afterward.. and ur program will start the server and running your application at once...
NB: you can use a different name from setup, any of your choice but the extension bat must be available