from MySql database to embedded database? - java

i made a javafx application using MySql database , and now i want to use an embedded database.
whitch do you think is most similar to mysql , because i don't want to change too much in my program "queries".

You could use SQLite.
For basic SELECTs and most CRUD operations is the same as any SQL server-based engine.

Related

Is it possible to create a database on fly in PostgreSQL for Azure using Java code if it does not exist? If yes, how?

I want to create database and tables on the fly in PostgreSQL in Azure cloud using Java code.
How to create a database in PostgreSQL for Azure using Java code if it does not exist?
Connect to the server through an Admin User
And run the following query:
CREATE DATABASE database_name OWNER your_owner;
For more information check this.
This is plain Java though, you have to check whether something like this is possible in Azure.

How can I use H2 database with laravel?

I am currently in a project and we need for some reason use h2 database. I would like to do an api in this project and I want to use laravel, because it is a framework I know to use. But I can't found information about connecting h2 database with laravel. Anyone knows how to do that? Is this even possible?
As per Laravel documentation:
Laravel makes interacting with databases extremely simple across a variety of database backends using either raw SQL, the fluent query builder, and the Eloquent ORM.
Currently, Laravel supports four databases:
MySQL 5.6+ (Version Policy)
PostgreSQL 9.4+ (Version Policy)
SQLite 3.8.8+
SQL Server 2017+ (Version Policy)
Reference:
Laravel -> Database -> Introduction

How to write a SQL so that it can be run on any database

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.

Accessing existing SQLite database using Eclipse

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.

How to store data into MySQL database?

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 .

Categories