Desktop app with local and online database - java

I want to create a Desktop App(Software), preferably in Java, which connects to a central MySQL DB on a local network whenever available.
I also want it to store and use a copy of the same DB when the central DB is not available, and sync whenever the central DB is available.
How can I store data locally, I mean which kind of database should I use for local database?
Also, are there any tools which speed up the Desktop App development?

Let's suppose that you will implement your solution in Java. You will need some classes (i.e. Data Access Obejcts, DAOs) in charge of interacting with the database on the network and on a file based database embedded in the application (the "local" database).
What you need:
A local database that you can ship with your application like H2 www.h2database.com, HSQLDB http://hsqldb.org/ or Derby db.apache.org/derby/.
To develop your DAOs (using JDBC or Hibernate) in such a way that you can instantiate them with different drivers, URLs, login/pwd and use only SQL standard / functions supported both by MySql and by the local DBMS. In practice you must avoid using DB specific functions.

You can use Hibernate or JPA for example, they have quite a nice and easy integration with your application.

Related

Managing Java based Desktop Applicationc(Database Management)

I am developing a Java based desktop application for a school.
As I am beginner, I am facing some issues.
Where to store the data of students or teachers (In files or database )
If in files, how I will ensure the security ?
If in Database, Can I embed db in application or I need to install db on server.
If db is installed on server, how I will manage the application if I will give that to other school users. (Means distributing the application to different users)
Do I need to create separate database for different users on servers or Can I make separate schema on same db.
First of all you need Mysql server installed for the following:
1->Store it in Database(mysql database)
2->database security (refer mysql secuity)
3->all you need is mysql connector for java put in the application folder of app you are creating
4->You can provide database inside of folder of application no
5->You can add user in same database.
You could do this:
1.Where to store the data of students or teachers (In files or database )
If you would like to go with open source databases, go with MYSQL instead of storing in files. Basic user authentication is enough to give you security to get started with your application. So no need of 2nd.
You can install and run on a remote system or your local machine depending on your application requirements and budgets.
On top your database, to communicate with it, develop a Spring web application (Spring data jpa) with REST web services so that any user can communicate with your application.
In your data base, you can manage users as well with basic authentication like username, password.
No you need not create separate schemas or dbs for each user. Instead you can create a single table that has information regarding Users for your application. For example, create a table "User_Management" which has columns like emailId, phone, name etc.
To get started, you can refer below:
http://javabeat.net/spring-data-jpa/
You should use Database (the best for this is Derby DB default for Java)
You can Embed Derby DB in application and also use this as server client.
Derby DB is light weight 2MB.
Alternatively you can use MySQL
If db is installed on server, You would create server on other school's PC or
you have to purchase the online server.
The Best as I described is Derby but if you want to use other you can use Xampp , Wampp server for local server client applications.

Derby access in IntelliJ?

I'm trying to learn the basics of database access, and I chose to use Derby. I'm using Embedder Derby, and I have IntelliJ set up so that it connects to Derby. However, when IntelliJ is connected to the database, my applications cannot access it. I know that I have to disconnect from the database from IntelliJ before attempting to access it with my application. Is there a way to set it up so that I can access the database with both IntelliJ and my application at the same time?
You cannot access the Embedded Database from more than one process, because when you run the Apache Derby database in embedded mode, only one Java process is created. The database process becomes an integral part of the process in which it was created.
However, you can use client/server mode to access the database with more than one application.

Android app extern database server

When I want to create an SQLite external database for android application, do I have to have a server with database that is always running?
Yes, since it will be on a server. If the server isn't running, then your application won't be able to get any data from the database.
There's a very important distinction that we're missing here - what it means to have a remote database.
SQLite is a flat-file embedded database engine. You don't have a separate process running SQLite in the background like you would one for MySQL or PostgreSQL or Oracle, nor would you really want to - SQLite as a database is pretty limited in what it can do.
If you say that you're going to have a remote SQLite database, then that implies that you have some server somewhere that writes to and reads from this flat-file database. If you can finagle that somehow, and make it secure, then more power to you - and yes, you could have this accessible remotely for your intents and purposes. Trust me though, you wouldn't want to.
What you're likely looking for is a way to remotely run MySQL or PostgreSQL instead, as these are proper database management systems (DBMS) which will be able to both service remote connections and give you a more expanded set of the SQL language.
Ultimately though, the database server must be running at all times. You wouldn't be able to connect to the database if it's down, and you don't know the lifespan of the app (or when it's going to be accessed, etc).
i got the below information from SQLite home page
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Based on the above statement you don't any server. I hope this information is useful to you.

Why h2 and mysql database locations are different in eclipse?

This is a stupid question and I know it, nevertheless I'd like to understand how these two databases are handled within my system.
I have eclipse IDE with two projects: h2_test and mysql_test, where h2_test is configured to use h2 database and mysql_test is configured to use mysql database.
In h2_test I have h2 location configured as String url = "jdbc:h2:~/h2_db" whereas in mysql_test as <property name="url" value="jdbc:mysql://localhost:3306/mysql"/>. As you might have guessed h2_test is a normal java project and mysql_test is dynamic web project.
When I run my h2_db my h2 database instance is created on my hard drive at ~/ directory.
When I run my msql_db my mysql database instance is created in memory?
I must add that to actually run mysql I had to install it and run as a system.service while for h2 all I had to do is to connect a h2 driver in eclipse. Why so much hassle with mysql?
Why I can't use the same logic with mysql db and create is as jdbc:mysql:~/mysql_db?
How are these set-ups different and which one is preferable for a web application?
h2 DB is a standalone database, that a single Java application loads directly and operates on. Usually, a single application can use a DB at a time. Other DBs of this sort are the key-value LevelDB and Java's DB4O.
MySQL, on the other hand, is designed to be more powerful, in that it is run in a server process (written in C++). Applications (a large number simultaneously) can connect to a given MySQL server (with authentication), even from different hosts.

Can I use an embedded Derby database in a client-server db environment one in future?

Can I use an embedded Derby database as non-embedded one in future? In this case will I need to migration or I will just need to change the driver in jdbc? If it is more complicated what will I have to do?
Yes, you can. A Derby database is identical, whether it's accessed by a standalone program using the embedded driver, or by multiple client programs communicating with the Derby network server.
The Derby network server is just some "glue" software which implements the DRDA remote database protocols to implement JDBC-over-the-net and then uses the normal embedded database access to access your database on the server side.
If you wish, there is even a slightly more advanced configuration called the "embedded server" which allows you to have your program which uses the embedded driver to access your database share that access with other networked clients by simultaneously acting as a networked server.
Here's some more information about that last option: http://db.apache.org/derby/docs/10.10/adminguide/radminembeddedserverex.html

Categories

Resources