0

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.

iceman2894
  • 67
  • 1
  • 9
  • 2
    emm do you want to connect your program directly to the file or what ? i dont understand ? – Maciej Cygan Feb 15 '14 at 15:17
  • What you want cannot be done with MySQL. There is no option to connect direct to a file. While [MySQL uses files internally](http://stackoverflow.com/questions/484750/restoring-mysql-database-from-physical-files) you can't ["connect"](http://stackoverflow.com/questions/15232755/how-to-connect-with-mysql-database-file-sql-using-directory-path-like-ms-acc) to files. Your best beat would be [MySQL Connector/MXJ](http://dev.mysql.com/doc/connector-mxj/en/connector-mxj.html), but it was discontinued a long time ago. – Anthony Accioly Feb 15 '14 at 15:34

4 Answers4

3

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 !

Maciej Cygan
  • 5,351
  • 5
  • 38
  • 72
  • ummmm yes you didn't understand me clearly I mean I have now my own java program that uses a connection of JDBC to connect to MYSQL to get data I want a way to only have a small .db file with the jar file data that have those data I get from the JDBC so instead I use a big connection from java to mysql I only make a small connection to a small .db file that is located with the data of my JAVA (jar) program understood ? – iceman2894 Feb 20 '14 at 00:26
  • @user2919656 sorry but i still dont get it. What do you mean by saying "...I use big connection from java to mysql" and that you want to ".. make small connection" – Maciej Cygan Feb 20 '14 at 14:31
  • my english is not good :P I mean that I have MySQL installed in the C drive it takes about 1.5 GB and I see lots of other Java Or C ++ programs that Have a small File named *.db and have the data needed I want to know How to do something Like that (have a small size of some KB and can be transferred on a USB withing the Jar) instead of re installing my SQL and copying the data on any computer I want to use my program with I think It's Clear now .. ? – iceman2894 Feb 20 '14 at 16:47
  • I think i do know what you mean. What you are referring to is probably a MySQL Program. What you can do is open MySQL program containing your database and find an option to " Export Database to a file ". This will give you option to save the database into a file (it wont be big ) However to access this database you will still need some program / host where this .db file can be uploaded – Maciej Cygan Feb 20 '14 at 16:53
  • okay you understood me now I will search for that export option now if you please teach me or show me an example how to remove the JDBC connection from the main MYSQL to reset it to just connect to that file I exported ? – iceman2894 Feb 20 '14 at 23:19
  • @user2919656 you can not connect directly to the .db file. Have a look at XAMPP they have a MySQL module, you can use that " as a host " and upload that .db file to the xampp. Then you can connect1 your program to the "host" which is xampp in this case. And the whole thing will weight a lot less than the MySQL program it self. Have a look also at Derby, its a build in Database. Maybe this will be more apealing to you – Maciej Cygan Feb 21 '14 at 10:05
  • okay So at the end I can't connect directly to the db file and I need a host okay got it but the data is sensitive I cant put it in another ones server any other suggestions ? – iceman2894 Feb 21 '14 at 15:44
1

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.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
0

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

iceman2894
  • 67
  • 1
  • 9
0

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