Converting a MySQL database to SQLite single file in java - java

I have MySQL installed, but It takes more than 1 GB of C drive. However the database file is only some KB's. I want to help to transfer the database file into single file that is in the Java program data folder. Also i want to know how to change the connection to be that file instead of using JDBC?
Thank you.
So a fast edit after long time ago 😂
that day i meant that I want to use something like SQLite instead of MySQL
I think that clarifies it now
waiting for new answers.

First of all, you questions is structured in a way that i do not fully understand it. However let me make things clear.
In order for java program to connect to Database you need a driver ( typically JDBC ). The database HAS to be on some sort of "server" i.e apache, sql server, derby etc. If you want to save some HDD space i suggest looking into Derby Database, which is "integrated" database
EDIT:
Or you can just host external database on some hosting server ;), there are some free ones out there too !

You might want an embedded database, like h2 or java Derby.
Such an embedded database often is stored as file, without external database engine runnin (it might do that too though). The API remains JDBC.

What I needed was mySQLite, it's saved on the device as a single file and easily managed through java.

What you need to do is to export the mysql database
And use dbmigration app to convert it to sqlite then use your database as you wish

Related

Java Netbeans Derby database for embedded system dilema: create the database with Netbeans or with code?

I read a lot of posts like:
querying embedded database in netbeans using derby
But still I'm having trouble to understand embedded databases.
1) I create a Derby database on Netbeans and I can create tables, link the database to a form and submit the data and update the records with no problem.
2) The problem arises when I want to make the program portable. I apply Clean and Build, then copy the dist folder and also copy the libraries, database, etc ... but when running the program does not recognize the database
3) I read in several places that it is appropriate that the database is created by code using something like
String host = "jdbc: derby: // localhost: 1527 / EmployeesCreateTrue; create = true"
and not creating the database on Netbeans Service...
If I do this procedure with code the database is created but it does not appear or does not allow me to connect from NetBeans and I wish I could fix it to create tables from NetBeans and not from code.
4) I read manuals "how to import a database from Derby to NetBeans" and it doesn't work...
Question: What is the best way to create a database, tables and connect to NetBeans for the final application to be easily portable?
1) Create the database on Netbeans with the wizzard?
or
2) Just plain code on the application?
I don't understand precisely what you mean by "the database is created but it does not appear."
I think if you were to explain that precisely, the community could probably help you.
There are three common reasons for "table does not exist" when you think you've created the tables; I've explained those cases in this answer: Is it necessary to create tables each time you connect the derby database?
Please let us know more information about your situation so that we can help you better understand the behavior of your application.
I'm not 100% sure if this is your problem, but a lot of problems people seem to have with Netbeans and Derby seems to come from the fact that they don't set derby.system.home explicitly. When you don't, Derby stores databases in the current directory, and that is likely different when working in the IDE, either in the Services tab, or your own code, than when you execute your app's jar as a standalone program. So the advice (which you will also find in the manual) is: always set derby.system.home. An alternative would be to use full paths to the databases, but that rarely works well for a real application that is deployed on different machines.
I had the same problem --had the derby db in the services but the netbeans coded programs didn't access it. I solved it by adding the derby database (copy paste) to the package in the Files section. I use Windows 7. Once I did that, I was able use multiple tables (before netbeans just ignored secondary tables and only allowed me to use the primary table).

Java, connect to mysql file without server

I wonder if it's possible to use the database file from mysql, without having a server running. Just copying the db file and place it somewhere, then use "jdbc:mysql://localhost:3306/table";
and change it to something like "jdbc:mysql://C:/Users/me/Desktop/table";
Will this work or is there a better way?
This is not possible with Mysql. Sqlite is a Serverless database designed for this purpose.
You're probably looking for an embedded database, i.e. as you say a library that is able to access a database on a file without a server.
MySQL has an embeddable version: http://www.mysql.com/oem/
You might want to check also H2: http://www.h2database.com/
Or Apache Derby: http://db.apache.org/derby/
Or HSQLDB: http://hsqldb.org/
Short answer: no.
Long answer: You'd have to basically recreate the MySQL daemon in Java. In particular, JDBC would have to know the structures inside of the file. The files are quite complicated, and this would be quite a pain.
This means you would have to basically write your own code capable of parsing and manipulating MySQL files. This would be a horribly complex task.
Yes, there is a better way. If you want to use MySQL, use MySQL.
Another option would be to use the embedded version of MySQL, or something like SQLite.

copy data from a mysql database to other mysql database with java

I have developed a small swing desktop application. This app needs data from other database, so for that I've created an small process using java that allows to get the info (using jdbc) from remote db and copy (using jpa) it to the local database, the problem is that this process take a lot of time. is there other way to do it in order to make faster this task ?
Please let me know if I am not clear, I'm not a native speaker.
Thanks
Diego
One good option is to use the Replication feature in MySQL. Please refer to the MySQL manual here for more information.
JPA is less suited here, as object-relational-mapping is costly, and this is bulk data transfer. Here you probably also do not need data base replication.
Maybe backup is a solution: several different approaches listed there.
In general one can also do a mysqldump (on a table for instance) on a cron task compress the dump, and retrieve it.

Using a local database for java application

I am currently undergoing a project which requires a database. So far uptil now I have been using a sql localhost database, I was wondering if there was an alternative to this.
Similar to micrsoft access database where I could read from the local database file instead?
It sounds like you are talking about an embedded database.
Take a look at: http://www.h2database.com/html/main.html
You could use Hypersonic or Derby; the latter is part of the JDK now. SQLite is another possibility.

The simplest Java SQL provider?

I need SQL functionalities for a Java JSE application, but dont need a whole SQL server, with things like listen on a port, connection string or even a standalone process to be runned or configured.
I also would prefer to work with files as storages, so that file path identifies DB data.
So given to the DB API the name of a file, I would need perform SQL with the file as DB storage, supporting tables, search, joins and inserts, without thinking to things like ports, external processes, server installation, ecc..
Without any other configurration action, since any other configurable feature is not needed.
Is there some library, preferrably installable as single .jar, that provides this functionality?
If there is not this library, which file-based DB is the simplest to configure and use within JSE, and which configuration steps are needed to perform a query in the provided DB and deploy it with (working) the java .jar application?
I suggest Derby db.apache.org/derby/
I like H2 Database very much. It compares very well with other database engines.
Sure, Hypersonic SQL or Derby, the database that comes bundled with Java 7, will both fill the bill. SQLite would be a third alternative.
you may want to check this out:
http://www.sqlite.org/
I have used HSQLDB in the past and liked it. Depending on what your needs are, you might also be interested in JoSQL which allows you to do SQL type of queries on java collections.

Categories

Resources