I have created a java application which stores data into MySQL database.
For that I have done the following things:
I have installed MySQL database on my computer.
I have created a database on that MySQL server.
I have created a table in the database with the required schema.
Now I want to deliver this application to various clients but my clients are not technical persons and I don't want to give instructions to each of my client to do the above three steps.
How can I integrate some functionality into my app so that it can do atleast step 2 and step 3 automatically so that the client needs to install only MySQL database.
It would be much better if the code can install the MySQL database automatically from the setup file attached with the application.
How the applications available in the market manage information?
For 2 and 3 you just need two SQL statements to run during installation: CREATE DATABASE and CREATE TABLE.
As an alternative I would suggest you to use SQLite for which your clients wouldn't need to install any database servers.
Personally, I like how Confluence (for example) deals with that:
The Confluence installation includes an embedded HSQLDB database, supplied for evaluation purposes. This is what you get when using the automatic installer on Windows.
As documented, the embedded database is Not Suitable for Production Instances of Confluence so they suggest to use an external database for production and provide detailed Database Setup Guides (installation, schema and user creation) for MySQL, PostgreSQL, Oracle, DB2, SQL Server and generic instructions for others databases.
The application will take care of creating the tables on startup if the schema is empty.
For those who prefer to create the tables manually, they provide a database creation script.
When upgrading to a higher version of Confluence, the Confluence application takes care of the schema update.
you can store data in two ways
using xampp
1st is using xampp/lampp/wampp and go to insert and just insert
using php
php used to insert data with mysql query
For steps 2 and 3 better create an OS shell script (bat or bash) that will execute mysql cli tool to create database and schema from your file
mysql -u root -p superpwd < create_database.sql
the create_database.sql better to create with help of mysqldump cli tool from your own database
Later you can include this script into your MySQL bundled installation.
I would think that you could do a data dump via phpAdmin which should script out the tables of the database along with insert statements for the actual data. I'm not a Java developer, but I think you should be able to use the functionality of the Java libraries that give you database access to turn back around and load your scripted out database as a file, read that file and then execute it against a database that you create via code.
Hope this helps for you.
For reference, here is how to create a mySql database via a command line .
Related
is it possible to read data from a local file without install a server
i use netbeans
If you want to simply read and write a file you can use the java.io or java.nio packages; if you want to access an .sql file as a database: you can't. It's not a database. You'll need to install a database on your pc to do such things.
SQL files are in plain text format and can comprise of several language elements. Multiple statements can be added to a single SQL file if their execution is possible without depending on each other. These SQL commands can be executed by query editors for carrying out CRUD operations. They do not contain any tables for accessing data.
Getting started with a database is fairly simple (if you follow instructions) and Netbeans has a built-in database, but I've never used it.
You can read about mysql here for example:
https://www.tutorialspoint.com/mysql/index.htm
And on how to connect to databases here:
https://www.tutorialspoint.com/jdbc/index.htm
I am making a JavaFX application (rental management software) and using MySQL database,
I was wondering how can I make my application works on my friend or client's PC since the database is on my PC? Is there is any way to configure the database on their PC without them doing all the installation processes of MySQL because they are not good with PC and it's not reliable to make the client set up the database I want to use a local database?
Server versus embedded
There are two kinds of database engines:
Those that run in their own process, as a separate app, accepting connections coming from any number of other apps on the same computer or over a network. This we call a database server. Postgres, MySQL, Microsoft SQL Server, Oracle, etc run this way.
Those that run within the process of an app, being started and stopped from that parent app, accepting connections only from within that parent app. This we call an embedded database engine. SQLite runs this way.
Some database products can run in either fashion. H2 Database Engine is one such product.
Given your situation, and given that H2 is written in pure Java, I suggest replacing your use of MySQL with H2. Run H2 in embedded mode.
Cloud database
Another option is for you to set up a database (MySQL or other) available to your users over the internets. You can run your own server. Or you can utilize any of several Database-as-a-Service (DBaaS) vendors such as Digital Ocean. This “cloud database” approach may not be practical for desktop apps because of unreliable internet connections, security issues around database passwords, and the challenges of multi-tenancy.
Repository design
By the way, you may want to learn about the Repository design approach in using interfaces and implementations as a layer of abstraction between your app and your database. This makes switching out database engines easier.
For example, your repository interfaces would declare methods such as fetchAllCustomers() and fetchCustomerForId( UUID id ). One implementation of that interface might be built for MySQL while another implementation is built for H2. The code calling methods on your repository interface knows nothing about MySQL or H2.
I am creating java desktop application. I have created exe of my jar file using exe4j. Now i am binding my sqlite database with my exe using easy binder software. But when i run my application the data is getting saved properly but when i rerun the application the data is not there which i have saved before. Please help
I have tried using the specific path i.e. stored the sqlite db file at specific location, it is working but it is not secure as any one can open the file.
I need to embed the database along with my application but the database is not saving the data when i rerun my application.
It sounds like your data is only getting temporarily stored because SQLite is using a transient in-memory database due to the fact that it can't find the specified database. Please specify what version of SQLite driver you are using, as well as an example of its use in your code.
Is you are worried about the security of someone accessing the database, then you may wish to consider another database besides SQLite.
I have to write an application (in server 1) that will generate a SQL. The SQL will be transferred to some different server (server 2). Another application which is deployed on server 2 will run the query on a database deployed in server 2.
Now there can be different types of database and the query will not be a simple one (may be 200 lines of query). Is there any third party application (like Hibernate) which I can use to create the query may be in a different format (like HQL), which can be transferred to server 2 and the application on server 2 will convert it to a DB specific SQL and run it?
I am using Spring & Java 8 to write the application.
Thanks in advance.
It is not possible for native sql query. But If you use any ORM technology like Hibernate then it is possible. Hibernate dailect will generate different database specific query for you. Though hibernate is an ORM technology it will defines relations with Objects that will represent your database table's. Popularly we call that objects as Entity. SO If you want to use different database then there will be no problem. But you have to change dailelect for different databases.
Why not use ORM - JPA or Hibernate and move queries to configurable different XML which works for each platform/DB? Deploy the XML based on DB...
No shortcut here but if you use ANSI SQL standards which is a platform-independent and is used as a base with most Database systems including Microsoft SQL Server, Oracle, MySQL, IBM DB2 etc you queries should work almost without any issues. Obviously you will loose on added features of DB's provide.
I have created an android app in java using eclipse which creates a SQLite database and lets the user add data to it.
I would like to know how to access an already existing SQLite database (say, in our web server) to view and add data to it ?
I Googled it and didn't get any clear picture. Do I need to install JDBC driver for doing this ?
Thanks.
SQLite is not a client/server database.
That said, the SQLite wiki mentions some alternatives.
If you want to access a remote database from your app, you will need an interface (like a web service) that will take requests from your app and actually do the database manipulation. If you just want to access a local database from your computer, there are several utilities for it to do it graphically or you can use sqlite3 to do it from the command line. If you want to access the database through your browser, I think you need a web service for that too.