I want to develop a website that works with MySQL, but at the same time I want that platform to be able to be used from desktop software. I'm doing it with java, and I'm new to it, I want to know how I could use a completely local database with java, which is MySQL, in such a way that I can use it as a mirror database, of which the website uses.
What you need is a distributed database, the changes you make in the master DB will be replicated in the slave DB, and the modifications can be made in several ways, this is a DB problem.
I recommend that you read the following article , where they explain this topic very well and help you to make an example.
The truth is that at the time of development, the database of a web app and a desktop app do not differ.
IMPORTANT: before connecting, you must create one
BBDD
withMySQL
its corresponding user and administrator password.If you don't want to complicate your life, use MySQL WorkBench or any other graphical interface
Register the driver in your system ( NOTE: the jar has to be in the classpath!!! ):
Configure connection to DB:
With
MysqlDataSource
(preferred form)Another older way is using
DriverManager
:Once done, you can make a query like this:
SOURCES 1 , 2
If the users are few and the local db can work in read mode, it is worth configuring a local replica of the master db used by the web server.
Edited 09-26-2016:
What you say can be done, but I don't know of any out-of-the-box solutions. I did it myself with a "dirty" table with two columns. Join the table that contained the dirty and its id. This way I could find locally modified ones easily and quickly, and more importantly, if there are local changes to sync.